I have exploring reactjs and noticed the two way of defining elemens/components.
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
};
}
const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);
And the functional approach :
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
They are are identical in terms of results. But functional appracoh is much more cleaner for me at least.
What brings the classing approach: From reactjs documentation:
This lets us use additional features such as local state and lifecycle hooks.
Is there any more advantages beside states, life cycle hooks of classing over pure functional approach?
When to use which one?