MSNCodeSNIPPETS← msncode.dev
snippets/react

useReducer for Complex State

Manage complex state transitions with reducer

reactjavascriptusereducerstate
JAVASCRIPT
const [state, dispatch] = useReducer((s, a) => a.type === 'inc' ? {count: s.count+1} : s, {count: 0});

More react snippets

Conditional Rendering (Short Circuit)

Render a component only if a condition is true

Forward Ref to Child Component

Pass a ref from parent to child component

Lazy Load a Component

Dynamically import a component to reduce bundle size

useCallback to Memoize Function

Prevent unnecessary re-renders by memoizing callbacks