Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

props to react router link

// Component 1 - Link with state
<Link to="/onboarding/profile" state={{ message: "hello" }}>Next Step</Link>
// Component 2 - Get the state
import { useLocation } from 'react-router-dom'
function Profile () {
  const location = useLocation()
  const { message } = location.state // "useLocation" to get the state
  console.log(message) // Console Output: hello
  
  return (...)
}
 
PREVIOUS NEXT
Tagged: #props #react #router #link
ADD COMMENT
Topic
Name
7+6 =