Though we can implement in both functional and class-based way, there are few fundamental differences between the two of them:
- Functional component can’t have stated ( before React hooks era ). It renders component only based on props passed. A class-based component can have a local state which can be helpful in building a bigger component
- Functional component access directly via props argument passed. In a class-based component, props are accessible via this.props.
- A class-based component is a more complex structure. It is an instance of a class derived from React. Component class. The class must implement a render() member function which returns a React component to be rendered
- The class-based component can also use lifecycle methods but functional component can’t use lifecycle methods.
- Functional components are a very light weighted component in comparison to class-based react component
Leave a Reply