
React18 Legacy Context
Migrate React class components from deprecated contextTypes and getChildContext to createContext without leaving silent undefined consumers.
Install
npx skills add https://github.com/github/awesome-copilot --skill react18-legacy-contextWhat is this skill?
- Documents full cross-file migration: context file, provider, and every consumer must update together
- Legacy context deprecated in React 16.3, warns in React 18.3.1, removed in React 19
- Ordered five-step playbook from provider discovery through consumer updates
- Explicit guard against partial migrations that yield undefined context at runtime
- Targets contextTypes, childContextTypes, and getChildContext class-component patterns
Adoption & trust: 622 installs on skills.sh; 34.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Frontend Designanthropics/skills
Vercel React Best Practicesvercel-labs/agent-skills
Remotion Best Practicesremotion-dev/skills
Vercel Composition Patternsvercel-labs/agent-skills
Develop Userscriptsxixu-me/skills
Next Best Practicesvercel-labs/next-skills
Journey fit
Primary fit
Legacy context removal is active frontend construction work on an existing React 18 codebase heading toward React 19. All steps target UI layer files: new context module, provider rewrite, and every consumer class or functional wrapper.
Common Questions / FAQ
Is React18 Legacy Context safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - React18 Legacy Context
# React 18 Legacy Context Migration Legacy context (`contextTypes`, `childContextTypes`, `getChildContext`) was deprecated in React 16.3 and warns in React 18.3.1. It is **removed in React 19**. ## This Is Always a Cross-File Migration Unlike most other migrations that touch one file at a time, context migration requires coordinating: 1. Create the context object (usually a new file) 2. Update the **provider** component 3. Update **every consumer** component Missing any consumer leaves the app broken - it will read from the wrong context or get `undefined`. ## Migration Steps (Always Follow This Order) ``` Step 1: Find the provider (childContextTypes + getChildContext) Step 2: Find ALL consumers (contextTypes) Step 3: Create the context file Step 4: Update the provider Step 5: Update each consumer (class components → contextType, function components → useContext) Step 6: Verify - run the app, check no legacy context warnings remain ``` ## Scan Commands ```bash # Find all providers grep -rn "childContextTypes\|getChildContext" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\." # Find all consumers grep -rn "contextTypes\s*=" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\." # Find this.context usage (may be legacy or modern - check which) grep -rn "this\.context\." src/ --include="*.js" --include="*.jsx" | grep -v "\.test\." ``` ## Reference Files - **`references/single-context.md`** - complete migration for one context (theme, auth, etc.) with provider + class consumer + function consumer - **`references/multi-context.md`** - apps with multiple legacy contexts (nested providers, multiple consumers of different contexts) - **`references/context-file-template.md`** - the standard file structure for a new context module # Single Context Migration - Complete Before/After ## Full Example: ThemeContext This covers the most common pattern - one context with one provider and multiple consumers. --- ### Step 1 - Before State (Legacy) **ThemeProvider.js (provider):** ```jsx import PropTypes from 'prop-types'; class ThemeProvider extends React.Component { static childContextTypes = { theme: PropTypes.string, toggleTheme: PropTypes.func, }; state = { theme: 'light' }; toggleTheme = () => { this.setState(s => ({ theme: s.theme === 'light' ? 'dark' : 'light' })); }; getChildContext() { return { theme: this.state.theme, toggleTheme: this.toggleTheme, }; } render() { return this.props.children; } } ``` **ThemedButton.js (class consumer):** ```jsx import PropTypes from 'prop-types'; class ThemedButton extends React.Component { static contextTypes = { theme: PropTypes.string, toggleTheme: PropTypes.func, }; render() { const { theme, toggleTheme } = this.context; return ( <button className={`btn btn-${theme}`} onClick={toggleTheme}> Toggle Theme </button> ); } } ``` **ThemedHeader.js (function consumer - if any):** ```jsx // Function components couldn't use legacy context cleanly // They had to use a class wrapper or render prop ``` --- ### Step 2 - Create Context File **src/contexts/ThemeContext.js (new file):** ```jsx import React from 'react'; // Default value matches the shape of getChildContext() r