Think in Components

Thinking in components is about being able to break down the UI into a Component hierarchy.

Each component will be created in a separate file.

// Store it in src/components/Greeting.js
function Greeting(){
  return <h1>Hello World</h2>
}

export default Greeting

Each component needs to be exported and then imported following the syntax of the ES6 module.

import Greeting from "./components/Gretting";

function App(){
  return <Greeting />;
}

export default App;

Just as you can compose functions or classes to create more complex solutions/models, you can compose simpler components to create more complex ones.

import Greeting from "./Title";
import Greeting from "./Content";
import Greeting from "./Comment";

function Article(){
  return (
    <Title />
    <Content />
    <Comment />
  );
}

export default Article;
import Greeting from "./components/Header";
import Greeting from "./components/Footer";
import Greeting from "./components/Sidebar";
import Greeting from "./components/Article";

function App(){
  return (
    <Header />
    <Sidebar />
    <Article />
    <Footer />
  );
}

export default App;