- Stateless Component as they do not hold or manage any state.
- Presentation Component because all they do is output UI elements.
Let's understand with an example. Create a file called “Functional.js” and write the following code.
- function Functional(){
- return <h1>Example of Functional Component</h1>
- }
Now, we can see that we have created a functional component but how can we use it? Or how can we connect it to the root component?
To connect it with the root component, first of all, export this function so that it will be available for other components. Now, after exporting, we can import it to any component where we want to use it.
- export default Functional;
Now, go to that component where we want to render it. We want to render this in our app component, so, go to app.js file and import it, like below.
- import Functional from './Functional';
After importing, use this function as a simple HTML tag inside the app, like below.
Both our pages look like this.
After importing use this function as a simple HTML tag inside the app.
- const Functional = () => <h1>Example of Functional Component</h1>
More about import and export
Whenever we export a component, we can import it with any name.
Name Export
Where we must import the component with the same name:
The class component basically maintains a private internal state or we can say it maintains some information which is private to that information to describe the user interface.