react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

feat: add react 19 codemods

Open DmytroHryshyn opened this issue 1 year ago • 2 comments

  • adds 7 react 19 codemods
  • adds ability to run ts transfroms from react-codemod CLI

Testing

Running with react-codemod

npx react-codemod remove-context-provider <path>
npx react-codemod replace-string-ref <path>
npx react-codemod remove-forward-ref <path>
npx react-codemod replace-use-form-state <path>
npx react-codemod use-context-hook <path>
npx react-codemod remove-memoization <path>
npx react-codemod replace-act-import <path>

Running with codemod

npx codemod react/19/remove-context-provider --target <path>
npx codemod react/19/replace-string-ref --target <path>
npx codemod react/19/remove-forward-ref --target <path>
npx codemod react/19/replace-use-form-state --target <path>
npx codemod react/19/use-context-hook --target <path>
npx codemod react/19/remove-memoization --target <path>
npx codemod react/19/replace-act-import --target <path>

DmytroHryshyn avatar Apr 30 '24 17:04 DmytroHryshyn

h/t @r4zendev @DmytroHryshyn , and @hbjORbj for creating the React 19 codemods.

alexbit-codemod avatar Apr 30 '24 21:04 alexbit-codemod

@acdlite, @rickhanlonii, @gnoff, @eps1lon, could one of you review this please? I'd like us to merge this PR as soon as possible, invite a few early adopters to test it even more before we market it more broadly. Thank you.

alexbit-codemod avatar May 02 '24 21:05 alexbit-codemod

@DmytroHryshyn can you allow edits to the PR?

rickhanlonii avatar May 13 '24 12:05 rickhanlonii

@DmytroHryshyn can you allow edits to the PR?

Sure, added you to the repo @rickhanlonii

DmytroHryshyn avatar May 13 '24 15:05 DmytroHryshyn

We do not recommend removing useMemo and use callback while the compiler is still experimental. The compiler may skip components for various reasons (violations of React’s rules, as-yet-unsupported syntax, etc) and a blanket codemod to remove all manual memoization could cause problems.

We strongly recommend waiting until the compiler is stable. We plan to provide a script that will only remove manual memoization where the compiler is running, skipping components/hooks where the compiler would bail out.

Let’s remove the “remove memoization” code of from the PR - thanks!

josephsavona avatar May 19 '24 00:05 josephsavona

noted. we will remove it soon. thanks for flagging.

alexbit-codemod avatar May 19 '24 01:05 alexbit-codemod

Thanks!

rickhanlonii avatar May 20 '24 21:05 rickhanlonii