Would a component of type
JavaScript
x
8
1
function App() {
2
const [state, setState] = React.useState()
3
4
return (
5
[ ]
6
)
7
}
8
be considered as a stateful component by the definition? Or would be still a stateless functional component since it does not extend React.Component
explicitly and does not declare a state with passing super(props)
?
Best regards, Konstantin
Advertisement
Answer
Stateless Component is when a component is purely a result of props alone, no state, the component can be written as a pure function avoiding the need to create a React component instance.
JavaScript
1
4
1
const Component = ({ name }) => {
2
return <>{name}</>;
3
};
4
So, if it is not stateless, it is a stateful component.
JavaScript
1
5
1
function App() {
2
const [state,setState] = React.useState()
3
return <>{state}</>
4
}
5