I am a beginner in React.
A.js
const obj ={
{name:objA, id:11111},
{name:objB, id:22222},
};
const [isRedirect, setIsRedirect] = useState(false);
xxxxxxx.....................
return(
obj.map((data) => (
<TableCell onClick = {setIsRedirect(true)}>
data.name
</TableCell>
{ isRedirect ?
<Redirect to={{
pathname:'/user-management',
state:{userID:data.id},
}} /> : "" }
)
)
user-management.js
useEffect(() => {
const history = createHashHistory();
if (history.location.state && history.location.state.transaction)
{
let state = { ...history.location.state };
delete state.transaction;
history.replace({ ...history.location, state });
}
console.log(props.location.state.userID); // show 22222
}
After I click the objA table cell, The code in user-management.js executes, but when I console.log(props.location.state), It shows the user id as 22222 instead of 11111. It seems props.location.state in user-management always stored the last value of json array obj. How can I modify to code? I would be grateful if u guys help. And Sorry for the code structure.