Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

URLSearchParams

import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";

function CheckoutDetails() {
  const location = useLocation();
  const [amountValue, setAmountValue] = useState(1);

  // function to get query params using URLSearchParams
  useEffect(() => {
    const searchParams = new URLSearchParams(location.search);
    if (searchParams.has("amount")) {
      const amount = searchParams.get("amount");
      setAmountValue(parseInt(amount, 10));
    } else {
      setAmountValue(1);
    }
  }, [location]);

  return (
  	<p>Amount: {amountValue}</p>
  )
  
Comment

generate query string from urlsearchparams

URLSearchParams.toString()
Comment

PREVIOUS NEXT
Code Example
Javascript :: nodejs sequelize find 
Javascript :: check contect type axios response 
Javascript :: how to add array object in javascript 
Javascript :: format phone number javascript 
Javascript :: postmark with nodejs 
Javascript :: fill array javascript 
Javascript :: split() javascript 
Javascript :: convert array to object with custom keys 
Javascript :: bind in javascript 
Javascript :: .includes meaning in javascript 
Javascript :: Convert mnemonic to seed in javascript 
Javascript :: uncaught exception javascript 
Javascript :: Return a Sorted Array Without Changing the Original Array 
Javascript :: express proxy 
Javascript :: router nodejs 
Javascript :: nuxt custom plugin 
Javascript :: check if user is streaming discord js 
Javascript :: Rounding off to desired no of digit after decimal 
Javascript :: angularjs How to get Capacitor Storage values before doing http call IONIC 6 
Javascript :: js check if string contains character 
Javascript :: change photo with js 
Javascript :: django pointfield json example 
Javascript :: apar chinmoy phy js code 
Javascript :: async function javascript dec 
Javascript :: acer swift 5 
Javascript :: HH:mm with am pm jquery 
Javascript :: cannon js parent child 
Javascript :: .includes javascript 
Javascript :: custom ngModel 
Javascript :: mock function jest 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =