Tags

References

References

0 lessons
7 code snippets
11 question banks
5 community items

references

Code Snippets

7 snippets
Code Snippet

React usePrevious Hook

Tracking the previous value of a prop or piece of state lets you diff renders, animate transitions, and detect specific change patterns. This snippet shows the canonical one-liner usePrevious, a useChanged variant that returns whether the value just changed, and a useHistory hook that keeps the last N values for undo / redo. All three are tiny but easy to get subtly wrong.

JavaScript
react
hooks
code-template
references

203

6

Easy
Code Snippet

React useIsMounted Hook

Setting state on an unmounted component throws a warning in development and can mask real bugs in production. The useIsMounted hook gives async callbacks a way to bail out before they touch React state. This snippet covers the basic ref-based hook, a useSafeState wrapper that no-ops after unmount, and a useSafeCallback variant that protects the function itself.

JavaScript
react
hooks
code-template
references

656

14

Easy
Code Snippet

Dynamic Object Property Access Patterns

Reading and writing object properties from a string key (or an array of keys) is one of the small skills that separates clean code from a sprawl of `if/else` chains. This snippet covers bracket access with `obj[key]`, safe nested reads with optional chaining and a path walker, and destructuring with computed and renamed keys. Use these patterns when keys come from config, query strings, or user input.

JavaScript
js-destructuring
js-optional-chaining
references

982

11

Easy
Code Snippet

Freeze, Seal, and preventExtensions on Objects

JavaScript ships three integrity levels for objects (`Object.preventExtensions`, `Object.seal`, and `Object.freeze`) and they are easy to confuse because each silently relaxes one rule from the next. This snippet builds them up from least to most restrictive, shows the strict-mode behavior that turns silent failures into errors, and finishes with a recursive `deepFreeze` for nested config. Reach for these when you want a runtime guarantee that downstream code cannot mutate a shared object.

JavaScript
immutability
references
js-strict-mode

840

12

Easy
Code Snippet

Cloning an Array (Shallow and Deep)

Most array clones in product code are shallow, which is exactly what `[...arr]`, `Array.from`, and `slice()` give you. The trap is nested data: shallow copies share inner references, so mutating a nested object inside the copy mutates the original. This snippet walks the modern shallow forms, the older idioms still in the wild, the `structuredClone` deep-copy answer for nested data, and an object-shaped sibling for contrast.

JavaScript
arrays
js-spread-rest
references

483

2

Easy
Code Snippet

Value-In-Array and Value-In-Object Checks

"Is X in this array?" and "is X anywhere in this object?" sound like the same question but call for different tools. Arrays have `includes` (which handles `NaN`), `indexOf` (which does not), and `Set.has` for hot paths. Objects need `Object.values` for a flat scan and a recursive walk for nested structures. This snippet covers both, with the gotchas that bite: `NaN`, hot-path scans, and shared object identity.

JavaScript
arrays
references
conditionals

605

13

Easy
Code Snippet
Premium

Proxy Patterns: Validation, Logging, Defaults

`Proxy` lets you intercept the basic operations on an object (get, set, has, deleteProperty) and run your own logic before or instead of the default behavior. This snippet shows three of the most useful patterns: a validating Proxy that rejects bad writes at the source, a logging Proxy that records access for debugging, and a defaults-plus-locked Proxy that supplies fallbacks and freezes keys after init. Use sparingly because Proxy adds a small per-access cost; reach for it when you need cross-cutting policy on a plain data object.

JavaScript
js-proxy-reflect
references
design-patterns

1k

21

Hard

Question Banks

11 items
Question Bank

JavaScript Object Reference and Key Coercion Traces

Six traces covering object-key stringification, reference vs literal equality, `Object.create` prototype chains, and shallow-copy aliasing with arrays.

JavaScript
quiz
references
immutability
js-language

430

2

Easy
Question Bank

JavaScript Array and Object Fundamentals Quiz

Test the day-one moves for working with arrays and objects: type-checking, copying, deduping, and the gotchas hiding under shallow vs deep clones.

JavaScript
quiz
arrays
references
fundamentals

759

21

Easy
Question Bank

JavaScript Immutability and References Quiz

Lock down objects with `Object.freeze`, build read-only properties with `Object.defineProperty`, and reason about why React leans on immutable updates.

JavaScript
quiz
immutability
references
interview-prep

968

5

Medium
Question Bank

Object Transformation Challenges

Six object-shape problems: building a tree from a flat array, valid-key extraction, chainable methods, stats reshaping, recursive leaf walking, and deep equality.

JavaScript
quiz
references
js-spread-rest
interview-prep

575

2

Medium
Question Bank

React Refs and Imperative Handles Quiz

Three drills on using refs to reach into the DOM, forwarding a ref through a wrapper component, and using useImperativeHandle to expose a controlled API.

JavaScript
quiz
react
references
hooks

222

2

Medium
Question Bank

JavaScript Immutable Object Key Removal: Two Approaches Quiz

Two seeded approaches to remove an object key without mutation (spread + delete, reduce + filter), plus two companions on destructure-and-drop and a deep-clone caveat.

JavaScript
quiz
references
immutability
js-spread-rest

1.1k

26

Easy
Question Bank

JavaScript Object Values to Array: Two Approaches Quiz

Two seeded approaches to convert an object's values to an array (Object.values spread vs Object.keys.map) plus two companions on Object.entries and ordering pitfalls.

JavaScript
quiz
references
arrays
fundamentals

1k

27

Medium
Question Bank
Premium

JavaScript Deep Object Comparison: Two Approaches Quiz

Diff the keys of two plain objects two ways (JSON.stringify shortcut and a recursive walker), plus two companions on circular references and a Map-based structural diff.

JavaScript
quiz
references
immutability
interview-prep

642

17

Hard
Question Bank
Premium

JavaScript Immutable Key Masking: Two Approaches Quiz

Mask the values of specified keys deeply, leaving the last three characters, two ways (recursive clone + mask and structuredClone + mask), plus two companions on path-based targeting and a JSON.stringify replacer variant.

JavaScript
quiz
references
immutability
interview-prep

385

11

Hard
Question Bank

JavaScript Merge Two Objects: Three Approaches Quiz

Three seeded ways to merge two plain objects (spread, `Object.assign`, and a manual `for...in` copy), plus two companions on shallow-vs-deep semantics and on which approaches mutate the target.

JavaScript
quiz
references
js-spread-rest
interview-prep

549

17

Medium
Question Bank

React Auto-Focus With Refs: Two Approaches Quiz

Two approaches to auto-focusing an input in React (`useRef` + `useEffect` vs the native `autoFocus` prop), plus companions on focusing after async state and on focusing inside a portal.

JavaScript
quiz
react
references
hooks

1k

28

Medium

Community

5 items
Code Snippet

Four Things I Forget About Create-React-App Every Year

Cheat sheet for the CRA quirks that keep coming back. Absolute imports via jsconfig, the HTTPS dev flag, the registerServiceWorker mystery, and the REACT_APP_ env var rules.

JavaScript
react
design-patterns
references

308

6

4.3 (13)

Mar 29, 2026

by @yunatorres

Code Snippet

The HOC + Render Props Patterns I Still Read in Legacy Repos

Hooks made HOCs and render props optional, but pre-2019 codebases still ship them. Four patterns to recognize when you inherit a Redux-era React app.

JavaScript
react
higher-order-functions
design-patterns
references

808

20

4.2 (11)

Mar 7, 2026

by @diyahassan

Code Snippet

Three React Router v4 Recipes I Inherit With Old Codebases

RRv4 still survives in long-running codebases. Three recipes I keep paged in: programmatic navigation via withRouter, query parsing, and a custom history singleton for non-React callers.

JavaScript
react
design-patterns
references

1k

31

4.1 (11)

Mar 3, 2026

by @freyadiallo

Code Snippet

Windowing a 10k Row List Without react-window

We had a 10k row list freezing scroll. react-window worked but was overkill for our shape. Here is the 60 line virtualizer we shipped instead.

JavaScript
react
performance-optimization
references

765

15

4.3 (10)

Feb 10, 2026

by @norapetrov

Code Snippet

The Three Ref-Driven Scroll Hooks I Actually Use

Four ref recipes that earn their keep: `scrollIntoView`, deps-driven scroll-to-top, multi-target callback refs in a Map, and the `forwardRef` + `useImperativeHandle` escape hatch.

JavaScript
react
hooks
references
js-dom

618

12

4.4 (15)

Nov 26, 2025

by @rajtanaka