Answers for "how to query params"

7

js get query param

const queryString = window.location.search;
const parameters = new URLSearchParams(queryString);
const value = parameters.get('key');
Posted by: Guest on June-25-2020
3

get query params

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>
  )
Posted by: Guest on September-12-2021
1

query parameters

Query Parameter 
		represented as  key value pair right after the ? 
		https://www.google.com/search?q=iloveyou
	usually used to filter the result
    
    GET /api/spartacus/search?gender=Male&nameContains=li
	if we have more than one query parameter 
		& is used to connect them 
        
 Also there is a Path Parameter|variable
	/api/spartans/{id}  /api/spartans/:id 
	It's used to identify single resource amonth list of resources
	in above example 
		the id is the path parameter to identify single spartan
Posted by: Guest on December-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language