Here’s a candy dispenser: Available Candy grab snickers grab skittles grab twix grab milky way Here’s how it’s implemented: function CandyDispenser() { const initialCandies = ['snickers', 'skittles', 'twix', 'milky way'] const [candies, setCandies] = React.useState(initialCandies) const dispense = candy => ...

I’ve given this blog post as a talk which you can watch here: The React Hooks feature was proposed in October 2018 and released ~4 months later in February 2019. Since then, people have been rapidly learning and adopting hooks ...

Watch “Implement useState with useReducer” on egghead.io Here’s the TL;DR: const useStateReducer = (prevState, newState) => typeof newState === 'function' ? newState(prevState) : newState const useStateInitializer = initialValue => typeof initialValue === 'function' ? initialValue() : initialValue function useState(initialValue) { ...

In my Learn React Hooks workshop material, we have an exercise where we build a tic-tac-toe game using React’s useState hook (based on the official React tutorial). Here’s the Github file for the finished version of that exercise We have ...

Watch “Implement Inversion of Control” on egghead.io If you’ve ever built code that was used in more than one place before, then you’re likely familiar with this story: You build a reusable bit of code (function, React component, or React ...