8 ms·
React has also been using classes for a long time (although the trend is to move away from them for performance and simplicity reasons). There is also a huge up
by azimuth11 7y ago
React has also been using classes for a long time (although the trend is to move away from them for performance and simplicity reasons). There is also a huge upward trend of people using TypeScript with React. Personally, after using TypeScript & Angular at work, I've preferred switching to TypeScript when using React in personal projects.
My main gripe with Angular (vs. React) has been the lack of first class support for patterns (higher order components) that have been a boon for React. It does look like Angular will have more 1st class support with Ivy[1], however, higher order components are so simple with React (and even better with TS/React).
[1]: https://blog.nrwl.io/metaprogramming-higher-order-components-and-mixins-with-angular-ivy-75748fcbc310 https://blog.nrwl.io/metaprogramming-higher-order-components...
- merb 7y ago> although the trend is to move away from them for performance and simplicity reasons I do not think that react classes will go away anytime soon. you can't represent state without them.
- pennaMan 7y agohttps://reactjs.org/docs/hooks-intro.html https://reactjs.org/docs/hooks-intro.html
- jaquers 7y agohttps://reactjs.org/docs/hooks-intro.html https://reactjs.org/docs/hooks-intro.html edit: Lol apparently two React devs ears were burning at the same time.
- merb 7y agowell 16.8 (which basically was the latest version) also btw: https://reactjs.org/docs/hooks-faq.html#do-i-need-to-rewrite-all-my-class-components https://reactjs.org/docs/hooks-faq.html#do-i-need-to-rewrite... and I still have no idea how I only do stuff on the client in a SSR environment (stuff that i did in componentDidMount)
- allover 7y ago> and I still have no idea how I only do stuff on the client in a SSR environment (stuff that i did in componentDidMount) The 'useEffect' hook - it won't be executed if you use e.g. ReactDOMServer.renderToString() for SSR useEffect(() => { console.log('Client side only'); }, []); Codesandbox: https://codesandbox.io/s/peaceful-dew-nvw83 https://codesandbox.io/s/peaceful-dew-nvw83
- azimuth11 7y agoWhile you wouldn't want to leave "console.log" in your code in production, you can use them in function components just like a classes' render methods. A better example (from the video "React Today and Tomorrow and 90% Cleaner React With Hooks" from October[1]) is something along the lines of updating document.title = `${some} Page` or possibly calling an API. [1]: https://www.youtube.com/watch?v=dpw9EHDh2bM https://www.youtube.com/watch?v=dpw9EHDh2bM
- allover 7y agoThe console.log was only there to illustrate that the code in useEffect's callback is only being run on the client-side (see the codesandbox I linked to). I think it's clear from the parent I was responding to that they have better use-cases in mind :)
- jaquers 7y agoBtw, totally agree about classes. I still like the 'look' of them for stateful components.
- preommr 7y ago> React has also been using classes for a long time And this > (although the trend is to move away from them for performance and simplicity reasons) Make me very frustrated because things like react became very popular for their simplicity. I read the reasoning the react team gave for hooks and I am not sure it justifies having such vastly different way of building components.
- asark 7y agoHooks are the biggest WTF for me in React-land, which is saying something. Classes and inheritance can lead to bad situations sometimes if you use them wrong, so we'll write our own method & property lookup table with a joke UI, then just not implement inheritance so that problem doesn't come up. I mean... what?