How to Pass Json data between two screens using useHistory hook in web

Viewed 20
const data = [
    { id: 1, name: 'Ford', color: 'Red' },
    { id: 2, name: 'Hyundai', color: 'Blue' },
    { id: 3, name: 'Hyundai', color: 'Blue' },
];
const routeChange = () => {
    navigate.push(`/newclaimreview`);
  };

Here I am navigating to newclaimreview screen upon clicking a button. How to pass data as a parameter and how to receive data in newclaimreview screen

1 Answers

You can pass data using state parameters from one screen to another screen like that.

navigate.push({
  pathname: '/newclaimreview',
  state: data_you_need_to_pass
});

You get params which you have sent in next screen

import { useLocation } from "react-router-dom";
const location = useLocation();
console.log(location.state);
Related