Creating a React Component is simple as 123 understanding what is needed to create a react component is essential in App creation. On this post I am going to show you three steps to follow in creating react Component whether class based or functional based.
Why am i writing about this as you already know i have been learning react and the journey has been very interesting with ups and down. My aim is to get you started without having going through a steep learning curve which i went through so that things can be simpler to you as you are going through this journey.
For that being said lets roll our shrive and get down into business.
React Component can be in two form one is class based and the other functional based all these two kind of Components can fall int stateful or stateless but lets leave this for future post and lets get down on component creation.
Step.1
import React from 'react';
while we are creating JavaScript functionality react adds some feature which are not JavaScript way of codding if we run the code without importing React we will get error to solve this issue our file need some help from React module that is why we have to import some of functionality.
Step.2
function MyApp(){} or class MyApp extends React.Component{}
Here we are going to create a class based Component or functional based component both of these components works the same but have some differences in data handling.Class based Component store data and maintain its state while functional component receives data and do nothing about it but display it.Class based component can be stateless if no state provided. I will elaborate this in deeper look on another post.
import React, { Component } from 'react'; class Button extends Component { render() { } } export default Button;
Step.3
After you have created your component its time to send it to the main component to render it to the Dom your job is to make it available to be rendered with export default
export default Button;
I be-leave that there are many main points that where not addressed here. But i hope you got some sense out of this post please leave a comment to help your boy do better.
Why am i writing about this as you already know i have been learning react and the journey has been very interesting with ups and down. My aim is to get you started without having going through a steep learning curve which i went through so that things can be simpler to you as you are going through this journey.
For that being said lets roll our shrive and get down into business.
React Component can be in two form one is class based and the other functional based all these two kind of Components can fall int stateful or stateless but lets leave this for future post and lets get down on component creation.
Step.1
import React from 'react';
while we are creating JavaScript functionality react adds some feature which are not JavaScript way of codding if we run the code without importing React we will get error to solve this issue our file need some help from React module that is why we have to import some of functionality.
Step.2
function MyApp(){} or class MyApp extends React.Component{}
Here we are going to create a class based Component or functional based component both of these components works the same but have some differences in data handling.Class based Component store data and maintain its state while functional component receives data and do nothing about it but display it.Class based component can be stateless if no state provided. I will elaborate this in deeper look on another post.
import React, { Component } from 'react'; class Button extends Component { render() { } } export default Button;
Step.3
After you have created your component its time to send it to the main component to render it to the Dom your job is to make it available to be rendered with export default
export default Button;
I be-leave that there are many main points that where not addressed here. But i hope you got some sense out of this post please leave a comment to help your boy do better.