Skip to content
Back to skills

React18 Legacy Context

ASecurity

Migrates the legacy React context API (contextTypes, childContextTypes, getChildContext) to createContext, which is deprecated in 18.3.1 and removed in React 19. Use when upgrading a codebase that still uses legacy context.

  • 14 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added October 10, 2026
ai-agentsbashreactgitapi

Works with

  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 10, 2026

npx -y skills add mouadja02/skills --skill react18-legacy-context --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React18 Legacy Context?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for React18 Legacy Context
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mouadja02-react18-legacy-context/badge)](https://www.skillsdirectory.com/skills/mouadja02-react18-legacy-context)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: react18-legacy-context
description: >-
  Migrates the legacy React context API (contextTypes, childContextTypes, getChildContext) to
  createContext, which is deprecated in 18.3.1 and removed in React 19. Use when upgrading a codebase
  that still uses legacy context.
source: "https://github.com/github/awesome-copilot"
attribution: "github/awesome-copilot by GitHub Community"
license: MIT
---

> **Attribution:** Sourced from [github/awesome-copilot](https://github.com/github/awesome-copilot) by [GitHub Community](https://github.com/github).

# 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

Files in this skill

  • SKILL.md2.1 KB
  • references/context-file-template.md3.2 KB
  • references/multi-context.md5.6 KB
  • references/single-context.md5.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.