DEV Community

Discussion on: Create react subcomponents in a simple way!

Collapse
 
gabrielmlinassi profile image
Gabriel Linassi

Very nice, thanks. I was facing weird errors but realized I was exporting like

Card.Header = ({ children }) => {
  return <div className="card-header">{children}</div>;
};
Enter fullscreen mode Exit fullscreen mode

instead of

const Header = ({ children }) => {
  return <div className="card-header">{children}</div>;
};
Card.Header = Header;
Enter fullscreen mode Exit fullscreen mode

So make sure to follow the proper syntax. Besides, As @harshdand said, you don't need the React.Children part.