“gancho uselocal” Código de respuesta

gancho uselocal

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

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

Usehistory React-Router-Dom

In react-router-dom version 6 
useHistory() is replaced by useNavigate() ;

import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
Joyous Jackal

reaccionar uselocation

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

uselocidad

// 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

uselocidad

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

Respuestas similares a “gancho uselocal”

Preguntas similares a “gancho uselocal”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código