Answers for "search params get react router dom"

3

get search params from url react

React Router Dom v6 
import { useSearchParams  } from 'react-router-dom'
//url  = http://localhost:3000/main/ride?type=send
let [searchParams, setSearchParams] = useSearchParams();
console.log(searchParams.get('type')); // send
Posted by: Guest on February-18-2022
0

window.location.search get parameters react

import { useLocation } from 'react-router';
import queryString from 'query-string';

const Dashboard: React.FC = React.memo((props) => {
    const location = useLocation();

    console.log(queryString.parse(location.search));

    // {__firebase_request_key: "blablabla", _k: "v9ifuf"}

    ...

    return <p>Example</p>;
}
Posted by: Guest on August-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language