replace-string-ref
Replace string refs in React class components with callback refs that assign through this.refs.
Usage
bash
Development
bash
Explore community-led codemods to migrate, optimize, and transform your codebase.
Build your own codemod and share it with the community.
Replace string refs with callback refs in React class components
npx codemod @react-new/replace-string-ref
Replace string refs in React class components with callback refs that assign through this.refs.
bash
bash
This is one example from the codemod's test cases. The codemod may handle many more cases.
Build your own codemod and share it with the community.
1 import React1, { PureComponent as PureComponent1 } from "react";
2
3 class C extends React1.Component {
4 render() {
5 return <div ref="refName" />;
6 }
7 }
8
9 class C1 extends PureComponent1 {
10 render() {
11 return <div ref="refName" />;
12 }
13 }
14