3 ms·
The latest consensus is to avoid class components, use only functional components and use hooks to handle state & side effects. Ninety percent of React is build
by ritchiea 6y ago
The latest consensus is to avoid class components, use only functional components and use hooks to handle state & side effects. Ninety percent of React is building DOM, hitting APIs with an HTTP client and using useState + useEffect. And remembering that you must pass functions & data to child elements to communicate between or share logic across components.
- poyu 6y agoWhat’s the reason to avoid class components though? The official tutorial still uses it, though that could just be because it’s outdated?
- ritchiea 6y agoThe zeitgeist is that hooks are easier to reason about than life cycle methods, functional components are more lightweight and result in less bundled code.
- hitekker 6y agoIt's more of a hype train than a "zeitgeist". Major community contributors like Jared Palmer have stepped forward in the past year to critique the complexity of React hooks. https://jaredpalmer.com/blog/react-is-becoming-a-black-box https://jaredpalmer.com/blog/react-is-becoming-a-black-box https://dillonshook.com/a-critique-of-react-hooks-addendum/ https://dillonshook.com/a-critique-of-react-hooks-addendum/ Personally, I think blindly adopting the latest frontend trends is the opposite of being "radically pragmatic".
- acemarke 6y agoThe React team is currently working on a complete rewrite of the docs, which will include a focus on hooks first: https://github.com/reactjs/reactjs.org/issues/3308 https://github.com/reactjs/reactjs.org/issues/3308 In the meantime, someone else ported the existing docs to teach function components and hooks in the examples: https://reactwithhooks.netlify.app/ https://reactwithhooks.netlify.app/