Code Explainers

Code explainers tagged #custom hooks

javascript
import { useCallback, useEffect, useState } from 'react';
 
export function useLocalStorage(key, initialValue) {
  const readValue = useCallback(() => {

How a useLocalStorage hook syncs state in React

custom hooks localstorage state persistence
Intermediate 8 steps
javascript
import { createContext, useContext, useReducer } from 'react';
 
const CartContext = createContext(null);
 

Building a shopping cart with Context in React

state management reducer context
Intermediate 10 steps