0 votes
in ReactJS by
What are stateful components in ReactJS? Explain with Example.

1 Answer

0 votes
by

If the behaviour of a component is dependent on the state of the component then it can be termed as stateful component. These stateful components are either function components with hooks or class components.

Let's take an example of function stateful component which update the state based on click event,

import React, {useState} from 'react';
const App = (props) => {
const [count, setCount] = useState(0);
handleIncrement() {
  setCount(count+1);
}
return (
  <>
    <button onClick={handleIncrement}>Increment</button>
    <span>Counter: {count}</span>
  </>
  )
}

Related questions

0 votes
asked Nov 3, 2023 in ReactJS by AdilsonLima
0 votes
asked Nov 4, 2023 in ReactJS by AdilsonLima
...