React Router/6/Seperate Link State Prop

1.0.1Last update Dec 17, 2024
by@manishjha-04

This codemod simplifies the Link component by transforming its to prop from an object with a pathname to a string. It removes the unnecessary object wrapper around the pathname, maintaining the state prop as is.

Before

<Link to={{ pathname: "/home", state: { from: "/login" } }} />

After

<Link to="/home" state={{ from: "/login" }} />

This change enhances the readability of your Link components by using a more straightforward string representation for the to prop, aligning with current best practices in React Router.

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now