The Why of a React Component
Ideas have been the cogwheel that drives technological advancement. In web development, developers have always commit the error tagged tautology (repetition) which an average English teacher would have avoided. The necessity to avoid repetitive task brought out what we known as components.
What is React Component
Some other frameworks such as Angular, Vue are all component-based. React component is simply a piece of reusable code block which is independent, that divides the UI into chunks.
Having components makes maintenance of codes and debugging very easy than having a thousands of lines of code together in one page file. React has two types of component viz: functional component and class component.
Class Component
Fig 1. above is a typic example of class component. Class component is more dynamic than functional component and hence includes constructors, render() method and state management. A typic class component is an ES6 class object which renders React Elements and is capable of maintaining it’s state.
Functional Component
A functional component could be seen as a JavaScript ES6 function which basically returns a react element and takes props as a parameter from a parent component.
This can be a regular function or an arrow function. A functional component has no state hence immutable. State is another topic on it’s own in react which i we would digest in another publication, stay tuned.