get data from mulitple query parameters react

Solutions on MaxInterview for get data from mulitple query parameters react by the best coders in the world

showing results for - "get data from mulitple query parameters react"
Isabel
09 Oct 2019
1import React from 'react';
2import {useLocation} from "react-router-dom";
3
4export default function Items() {
5 //Where parameter url = localhost:3000/items?name=pen&id=12
6  const search = useLocation().search;
7  const name = new URLSearchParams(search).get('name');  const id = new URLSearchParams(search).get('id');
8  return (
9    <div>
10      <h1>Items page</h1>
11      <p>{id}</p>      <p>{name}</p>    </div>
12  );
13}
similar questions