Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

usenavigate and uselocation in react

// on first component
import React from "react";
import { useNavigate } from "react-router-dom";

const Component1 = () => {
  const navigate = useNavigate();
  return (
    <button onClick={() => navigate("/store", { state: "an object or single value" })} >
    Click Me
    </button>
  );
}

// on 2nd component
import React from "react";
import { useLocation } from "react-router-dom";

const Component1 = () => {
  const data = useLocation();
  console.log(data)
  return (
    <div>got the data</div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use react typed js 
Javascript :: google translate javascript 
Javascript :: is displayed 
Javascript :: knex.raw postgres how to add multiple parameters 
Javascript :: Replace symbol if it is preceded and followed by a word character js 
Javascript :: how to change created_at format with javascript rails 
Javascript :: generate svg from javascript 
Javascript :: exceljs font family 
Javascript :: trigger sweet alert through javascript 
Javascript :: react using button props child 
Javascript :: es6 closures 
Javascript :: react state management 
Javascript :: mongoose autoincrement 
Javascript :: js how to get element csswidth 
Javascript :: expo location background example 
Javascript :: cypress element length 
Javascript :: scss in react app 
Javascript :: get user location javascript 
Javascript :: how to add a class in classlist and remove after 100 ms using jquery 
Javascript :: como colocar dados no firebase 
Javascript :: api streamelements watchtime 
Javascript :: window.history 
Javascript :: js email validation 
Javascript :: js startswitch 
Javascript :: foreach loop 
Javascript :: how to add multiple style attributes in react element 
Javascript :: jquery rename id 
Javascript :: js string to charcode array 
Javascript :: array.find 
Javascript :: javascript tousand seperator 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =