Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useLocation react

import { useLocation } from "react-router-dom";

function Locaions() {

  let location = useLocation();

  return (
    <>
    {location.pathname === "/Home" ?
    "Hi i am at the homepage"
    :
    "d-none"
    }
    </>
  );
}
Comment

useLocation

// React Router v6: hook returns current location object
import { useLocation } from 'react-router-dom'

function App() {
  let location = useLocation()
  
  useEffect(() => {
    ga('send', 'pageview')
  }, [location])
  
  return (/*...*/)
}
Comment

useLocation

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

PREVIOUS NEXT
Code Example
Javascript :: jquery get document height 
Javascript :: js check if string is base64 
Javascript :: obj[key].includes is not a function 
Javascript :: javascript upload json 
Javascript :: in array in js 
Javascript :: Check your Homestead.yaml (or Homestead.json) file, the path to your private key does not exist. 
Javascript :: javascript log error without traceback 
Javascript :: how to add onclick event in javascript 
Javascript :: jquery ajax type json 
Javascript :: create parent div javascript 
Javascript :: node js get file name without extension 
Javascript :: javascript to convert rgb to hsl 
Javascript :: tostring javascript 
Javascript :: toggle multiple classes jquery 
Javascript :: angular mat select open programmatically 
Javascript :: react router Link does work 
Javascript :: get nearest multiple of a number javascript 
Javascript :: javascript loop through object 
Javascript :: refresh page scrolltop 0 
Javascript :: public class NameOf { public static String nameof<T(Expression<Func<T name) { MemberExpression expressionBody = (MemberExpression)name.Body; return expressionBody.Member.Name; } } 
Javascript :: how to play music in js 
Javascript :: placeholder in angular 9 select with working required 
Javascript :: how to take create array using jquery 
Javascript :: make js file windows command 
Javascript :: veu scroll to top 
Javascript :: find the key of a value in array js 
Javascript :: refresh page after delete angular 
Javascript :: console log returns object object 
Javascript :: check if the data can be parsed javascript 
Javascript :: uuid javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =