React-router V4 - Replace Location Query

verified codemod icon

This codemod replaces instances of location.query with parse(location.search), where parse is a function imported from query-string.

React Router
jscodeshift
Estimated time saving
~3 minutes/occurrence
Change mode
Autonomous
Applicability criteria

React Router version 3.x.y

Made by
Codemod.com
Codemod.com

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod react-router/4/replace-location-query
copy CLI command icon

Codemod VS Code extension:

intalling vs code extension tooltip icon
vs code logo
Run in VS Code

Description

This codemod replaces instances of location.query with parse(location.search), where parse is a function imported from query-string.

Before

const List = ({ location }) => (
	<div>
		<h1>{location.query.sort}</h1>
	</div>
);

After

import { parse } from 'query-string';
const List = ({ location }) => (
	<div>
		<h1>{parse(location.search).sort}</h1>
	</div>
);