react-19-remove-legacy-context
Remove legacy childContextTypes and getChildContext() usage from React class components and wrap rendered JSX with a new context.
Usage
bash
Explore community-led codemods to migrate, optimize, and transform your codebase.
Build your own codemod and share it with the community.
Remove legacy childContextTypes/getChildContext usage from React class components
Build your own codemod and share it with the community.
1 import PropTypes from "prop-types";
2 import React from "react";
3
4 class Parent extends React.Component {
5 static childContextTypes = { foo: PropTypes.string.isRequired };
6 getChildContext() { return { foo: "bar" }; }
7 render() { return <Child />; }
8 }
9
10 class Parent2 extends React.Component {
11 static childContextTypes = { bar: PropTypes.string.isRequired };
12 getChildContext() { return { bar: "baz" }; }
13 render() { return <Child2 />; }
14 }
15