Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

can i pass data with usenavigate react router

import {Link, useNavigate} from 'react-router-dom';

function ComponentA(props) {

  const navigate = useNavigate();

  const toComponentB=()=>{
navigate('/componentB',{state:{id:1,name:'sabaoon'}});
  }

  return (
   <>
<div> <a onClick={()=>{toComponentB()}}>Component B<a/></div>
</>
  );


}


export default ComponentA;
Comment

can i pass data with usenavigate react router

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

 function ComponentB() {

    const location = useLocation();
   
        return (

            <>
               
<div>{location.state.name}</div>

            </>
        )
    }

export default ComponentB;
Comment

PREVIOUS NEXT
Code Example
Javascript :: TypeError: this.authenticate is not a function 
Javascript :: column.footer jquery 
Javascript :: add css class to html in js 
Javascript :: js text word wrap 
Javascript :: contains whitespace js function 
Javascript :: golang parse jason 
Javascript :: javascript conver time into 24 hour format 
Javascript :: remove duplicates from array 
Javascript :: how to include a css file in jsp 
Javascript :: Sort number in descending order 
Javascript :: how to disable back js 
Javascript :: on enter key press react js 
Javascript :: how to find all permutations of an array with javascript 
Javascript :: jquery loop through collection backwards 
Javascript :: owl carousel get started 
Javascript :: add class jquery 
Javascript :: react native image blur 
Javascript :: javascript create element with class 
Javascript :: how to do radio button validation in jquery 
Javascript :: convert node.js to ES6 
Javascript :: vs code open file in new window 
Javascript :: javascript check if string contains substring 
Javascript :: mac node change version 16 
Javascript :: duplicate value removed in array of object in javascript 
Javascript :: esversion 9 
Javascript :: js markdown to html 
Javascript :: next js material ui typescript 
Javascript :: javascript copy some properties from one object to another 
Javascript :: print page in javascript 
Javascript :: run jest on single file 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =