“USELOCATION bereaksi” Kode Jawaban

Hook Uselocation

import { useHistory } from 'react-router-dom';

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
Repulsive Rook

UseHistory GOBACK

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

const history = useHistory();

<button onClick={() => history.goBack()}>Go Back</button>
Defeated Dogfish

USELOCATION bereaksi

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

function Locaions() {

  let location = useLocation();

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

reaksi router dom arus hook

import { useLocation } from 'react-router-dom'

// Location is, for example: http://localhost:3000/users/new

// Care! MyComponent must be inside Router to work
const MyComponent = () => {
	const location = useLocation()
    
    // location.pathname is '/users/new'
    return <span>Path is: {location.pathname}</span>
}

export default MyComponent
Mr Dom

Uselokasi

// 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 (/*...*/)
}
Coffee Addict

Uselokasi

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>
  )
  
Inquisitive Iguana

Jawaban yang mirip dengan “USELOCATION bereaksi”

Pertanyaan yang mirip dengan “USELOCATION bereaksi”

Lebih banyak jawaban terkait untuk “USELOCATION bereaksi” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya