Answers for "react parameter value from query string"


react parameter value from query string

// As far as I know there are three methods you can do that.
// Suppose an URL looks like this

// 1) use a third library called 'query-string'.
import queryString from 'query-string'

const value=queryString.parse(;
const token=value.token;

// 2) Without library - Get a single query string
const query = new URLSearchParams(;

const token = query.get('token')

// 3) One liner - Get query string with '&' and without any library
const getQueryParams = () =>'?', '').split('&').reduce((r,e) => (r[e.split('=')[0]] = decodeURIComponent(e.split('=')[1]), r), {});
Posted by: Guest on April-25-2021

Code answers related to "react parameter value from query string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language