I am trying to create a component Book, which has a header, and I want to be able to import it in App.js as shown in the code below, I am fairly new to react and I do not know how to look up for it because I don't know how this concept is called. How can make a component Book and that component has other non functional components such as Book.Header for a header book or Book.Title, and that I can use as shown in the App.js
const Book = () => (
<div className="book">
<Book.Header />
</div>
);
Book.Header = ({child}) => (
<div><p>{child}</p></div> // here should render the text from Book.Header in App.js
);
export default Book;
And in App.js
import Book from "./components/Book";
function App() {
return (
<div className="App">
<Book
<Book.Header>My book header</Book.Header> // I want to render this in
// Book.Header
>
</Book>
</div>
);
}
const Book = { Book: BookComponent, Header: HeaderComponent }and then just default export it.export default Bookexport const BookHeader = () => {...}keep the default book export and then your import would beimport Book, { BookHeader } from './components/book'