Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to type a react composition component pattern with dot notation

I am having some trouble understanding how to properly type a classic simple react composition pattern.

Say i have a Team component that takes a Team.Players children component. Typescript is telling me that the Players property does not exist in the type definition of Team, how can i fix this ?

import './App.css'
import Team from './components/team/Team'

function App() {

  return (
    <div className="App">
      <Team>
        <Team.Players />
        <Team.Victories />
      </Team>
    </div>
  )
}

export default App
// type imports
import { TeamProps } from "../../types/TeamTypes"
import Players from './Players'
import Victories from './Victories'

const Team = ({children}: TeamProps) => {
  Team.Players = Players
  Team.Victories = Victories
  return (
    <div>
      {children}
    </div>
  )
}
export default Team
const Players = () => {
  return (
    <div>
      Playersss
    </div>
  )
}

export default Players
export type TeamProps = { 
  children:  JSX.Element,
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It should be more like:

const Team = ({children}: TeamProps) => {
  return (
    <div>
      {children}
    </div>
  )
}

Team.Players = Players
Team.Victories = Victories

export default Team
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading