I want to pass an array of numbers from one component to another (from one page to another) in my React app, by using onClick of a button. I currently do it using state and "useLocation" from 'react-router-dom". It works, but I'm not sure if this is the most efficient way to do it. The array that I'm passing can be up to a 1,000 elements long. Could anyone advise me on what is the best practice here?
Here's how I pass the data:
function onClickExample() {
navigate(REVIEW, {state: {IDs: dueReviewIDs}})
}
Here's how I retrieve data:
const { state } = useLocation();
const IDs = state.IDs;
I have read other answers, but they don't focus on the specific case of passing data using onClick (rather than simply passing parameter to a child component). (For example: How to pass an array of items in React.js)
Would, for exmample, using LocalStorage be a more reliable option?