14

Say I have a component that takes 2 button instances:

export interface GridProps {
  backButton: any;
  nextButton: any;
}

Should the type for the button be React.ReactNode or React.ReactElement

so either:

export interface GridProps {
  backButton: React.ReactNode;
  nextButton: React.ReactNode;
}

or

export interface GridProps {
  backButton: React.ReactElement<any>;
  nextButton: React.ReactElement<any>;
}

1 Answer 1

20

React.ReactNode is more convenient way for passing markup to child components. It contains everything you can insert in JSX like <div>{passedContent}</div> It is used in many React component libraries. It makes sense to use React.ReactElement<any> only if you want to restrict customization to elements of particular class. For example React.ReactElement<ButtonProps>. It is useful if you want to clone passed element and append some props to it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.