React 18 Legacy Context Migration

React 18 Legacy Context Migration

Walks through migrating React legacy context (contextTypes, getChildContext) to createContext, updating the provider and every consumer together before React 19.

Skill files4 files

references/

SKILL.md48 lines
1
---
2
name: react18-legacy-context
3
description: 'Provides the complete migration pattern for React legacy context API (contextTypes, childContextTypes, getChildContext) to the modern createContext API. Use this skill whenever migrating legacy context in class components - this is always a cross-file migration requiring the provider AND all consumers to be updated together. Use it before touching any contextTypes or childContextTypes code, because migrating only the provider without the consumers (or vice versa) will cause a runtime failure. Always read this skill before writing any context migration - the cross-file coordination steps here prevent the most common context migration bugs.'
4
---
5
6
# React 18 Legacy Context Migration
7
8
Legacy context (`contextTypes`, `childContextTypes`, `getChildContext`) was deprecated in React 16.3 and warns in React 18.3.1. It is **removed in React 19**.
9
10
## This Is Always a Cross-File Migration
11
12
Unlike most other migrations that touch one file at a time, context migration requires coordinating:
13
1. Create the context object (usually a new file)
14
2. Update the **provider** component
15
3. Update **every consumer** component
16
17
Missing any consumer leaves the app broken - it will read from the wrong context or get `undefined`.
18
19
## Migration Steps (Always Follow This Order)
20
21
```
22
Step 1: Find the provider (childContextTypes + getChildContext)
23
Step 2: Find ALL consumers (contextTypes)
24
Step 3: Create the context file
25
Step 4: Update the provider
26
Step 5: Update each consumer (class components → contextType, function components → useContext)
27
Step 6: Verify - run the app, check no legacy context warnings remain
28
```
29
30
## Scan Commands
31
32
```bash
33
# Find all providers
34
grep -rn "childContextTypes\|getChildContext" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."
35
36
# Find all consumers
37
grep -rn "contextTypes\s*=" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."
38
39
# Find this.context usage (may be legacy or modern - check which)
40
grep -rn "this\.context\." src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."
41
```
42
43
## Reference Files
44
45
- **`references/single-context.md`** - complete migration for one context (theme, auth, etc.) with provider + class consumer + function consumer
46
- **`references/multi-context.md`** - apps with multiple legacy contexts (nested providers, multiple consumers of different contexts)
47
- **`references/context-file-template.md`** - the standard file structure for a new context module
48

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…