DEV Community

Discussion on: Passing Props to Child Components in React using TypeScript

Collapse
 
gerreth profile image
Gerret Halberstadt

Hey, while in your example it makes sense to give the component an implicit children prop, in the article above it might be misleading. Someone could be using something like

<Form
  state={state}
  setState={setState}
  handleOnSubmit={handleOnSubmit}
  placeholder="Type some letters"
>
  Some info text
</Form>
Enter fullscreen mode Exit fullscreen mode

and wondering why the text is not rendering without TypeScript complaining. You could instead write it like

const Form = ({state, setState, handleOnSubmit, placeholder}: Props) => {
  // ...
}
Enter fullscreen mode Exit fullscreen mode

and do not lose something too useful. I stumbled upon github.com/typescript-cheatsheets/... (Why is React.FC discouraged?) a while ago and thought it could be useful to share here.

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

Thanks for sharing! Undoubtedly a good resource to study. 🤓