A workshop which dives deep into all React built-in hooks
- The heart of this document are the "CodeSandBox" links. Most of them are written in TypeScript, some in JavaScript (marked by "(JS)")
- One part of the document is a journey which gradually introduces hooks via
<Counter />
scenarios. - Besides there are other examples which cover other hooks or interesting points concerning hooks.
-
- dependency array
- how to prevent race conditions when fetching data
-
- Covering "Removing dependencies: functions" heuristics
-
useEffect
anduseState
interplay- Covering "Removing dependencies: values" heuristics
-
Topics covered:
useLayoutEffect
vs.useEffect
- a-typical use of
useState
setter function useEffect
/useLayoutEffect
dependency array with refs- React hooks lifecycle
-
React.memo
HOC performance improvementTopics covered:
- how to avoid unnecessary React re-renderings
- Interplay with
useCallback
hook - How change in props triggers re-renderings
- Discussion of code organization
usePrevious
hookuseState
error:setState
on unmounted component- batched
useState
calls - React Strictmode
- The provided links to the React library are from its
server
implementation. They however exemplify their functionality better then the hook definitions in other parts of the React codebase because they are more abstract there. - Working through all of the examples as part of a workshop will take at least one day, more realistically 1.5 days.
- This is a living document and far from perfect. I'll gradually improve it here and there and add new notes and examples.
This course is a collection of code examples which were inspired by other blog articles and code snippets written by wonderful developers. Sometimes I just adapted them from others. I learned a lot from them while working through their articles and examples. Thanks so much! The sections sometimes contain links to other helpful articles.
I have to point out one article in particular here: Many examples in this course are based on Dan Abramov's blog article A Complete Guide to useEffect. Thanks for this very enlightning read!
And a huge thanks to all my students with whom I worked through the examples. Your questions and comments are continuously improving this course. Thanks!
- React eli5 Eli5 (explained like a 5 years old) are great articles for every topic. It's great that there's one for React, too.