0

When I using function component and when I using class component in react because when I work with react.js I can't understand what difference because the function and class component is work fine

1

2 Answers 2

1

Shortly, Class Components:

  1. Have their own state to implement some logic to your app;
  2. Have Lifecycle methods (componentDidMount(), componentDidUpdate(), etc);

Functional Components are simple JS functions that accept props and return a React element, without any changes.

This article might also help

Sign up to request clarification or add additional context in comments.

Comments

0

Nowadays the differences of use between class based components and functional ones are very few.

Just a little implementation to what @airblade said: while class components have a state and Lifecycle methods, from October 2018 (I might be wrong on the date), functional components have the so called hooks: functions that simulate state or Lifecycle methods for functional components.

Personally I only use functional components since I have recently started programming in React and looks like that's where React is heading to.

There's this good article on Medium that explains the use of React Hooks: React Hooks — How To Use useState and useEffect Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.