What's a good example of when I should use a class vs JSX object in React. I noticed my projects seem to be overflowing with class Foo extends React.Component{} when I could simply be using a JSX object. Would it be only if I don't need to use the react life-cycle and state variables?
Asked
Active
Viewed 170 times
0
-
2Probably you meant for [Class vs Functional Component](https://stackoverflow.com/questions/38926574/react-functional-components-vs-classical-components)? – Bhojendra Rauniyar Aug 25 '20 at 18:41
-
With the hooks api you can use jsx for virtually everything except for very few edge cases. Statefull vs stateless component argument is very outdated. – Antoine Eskaros Aug 25 '20 at 18:41
-
1React uses JSX so even class based component has JSX. Thus, I am not quite clear what you're asking for? – Bhojendra Rauniyar Aug 25 '20 at 18:44
-
If you mean FC and not JSX, it's very situational when you should or should not use one or the other. You should pick one and be consistent. I _generally_ prefer functional components (FC), because I like hooks and prefer the simple API. FC don't have `componentDidCatch` so if you need something like that, you'll need to wrap them in your own error boundary. Some prefer classes. It ***really*** just boils down to preference unless you want to add some concrete examples to your question. – zero298 Aug 25 '20 at 18:45