footer: React Hooks...wat? slidenumbers: true autoscale: true theme: Next, 9
- Short presentation 📊 (~5mins)
- Introductory walkthrough demo 💻 (~15mins)
- Finish presentation 📊 (~5mins)
- Remaining ~3 working demos 💻
^ Who here has heard of hooks? Used hooks? Read about hooks?
- They let you use state and other React features without writing a class
- Functional components now have feature parity to class components
- You "hook" into React's state management system
- Opt-in gradually, no breaking changes
Two basic but vv important rules:
⚠️ Only call hooks at top level of function (no loops, conditions or nested fxns)⚠️ Only call from React function components or custom hoooks (we'll get to that)
^ Won't make a ton of sense right now but important for the demo
Easier to show than to continue explaining
- Cleaner separation of functionally-similar stateful logic ✨
- Sharing of stateful logic easier between components (fewer render props and HOCs)
- Standardization of component composition 🤓
- Declarative implementation of lifecycle events 💪
- Side-effects separated from component logic
- Opt-in, no breaking changes
- May reduce reliance on Redux
- New paradigm 🤔
- Numerous ways to create component 😵
- Reliance on call-order may be unnerving 😔
- Declarative implementation of lifecycle events 😕
Two basic but vv important rules:
⚠️ Only call hooks at top level of function (no loops, conditions or nested fxns)⚠️ Only call from React function components or custom hoooks (we'll get to that)
- Rules not enforced but will fail at runtime
- Custom hooks adhere to
useFoo()
naming convention (lintable) - Linting is a must
Below is a list of resources used to compile this repo's information.
- Comment in RFC explaining call-order reliance
- React Conf 18 Hooks keynote
- Making sense of React Hooks by Dan Abramov
- Official Docs - Hooks at a Glance
- Official Docs - Building Your Own Hooks