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 :: rotate array by d elements javascript 
Javascript :: eslint disable tag 
Javascript :: how to get date in footer javascript 
Javascript :: es6 features javascript 
Javascript :: min and max javascript 
Javascript :: find object in json array 
Javascript :: js wait for element to load 
Javascript :: js map object to array 
Javascript :: send mail in node js without password 
Javascript :: change text in javascript 
Javascript :: how to kill all node processes 
Javascript :: apollo server change port 
Javascript :: how to add data to array in javascript dynamically 
Javascript :: jquery find tag and class 
Javascript :: hypot javascript 
Javascript :: jquery get element tag 
Javascript :: how to go back one directory in git bash 
Javascript :: filter dates javascript 
Javascript :: js listen localstorage change 
Javascript :: can we send raw json in get method in flutter 
Javascript :: react native password strength 
Javascript :: innertext of input js 
Javascript :: json full form 
Javascript :: classlist 
Javascript :: aggregate mongodb 
Javascript :: javascript bitwise operators 
Javascript :: fullcalendar react add event duration 
Javascript :: how to import a json string from a file in typescript 
Javascript :: how to include script file in javascript 
Javascript :: how to delete a message by its id discord.js 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =