Skip to content

QuizNot attempted

Passing a component as a prop

A <Private component={Profile} /> route renders <Component name="settings" /> when logged in. How should the component prop be typed?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • React.ComponentType<ProfileProps>
  • ComponentType<P> is a function or class component that accepts props P, so the route can render it as <Component {...props} /> and TS checks the props you pass.
  • Not React.ReactNode: that is already-rendered output (<Profile />), which you can't give new props.
  • Not React.JSX.Element: same, an element rather than a component.
  • Not () => void: a component returns something renderable and takes props.