Computer Science/React
React navigate를 통해 state 전달하기.
imygnam
2022. 8. 17. 01:39
보내는 쪽
import { useNavigate } from 'react-router';
const goToDetail = (s) => {
navigate('/detail', {state : {id : s.championInfoList }});
};
navigate에 state로써 객체를 전할해 주면 된다.
<div onClick={() => goToDetail(s)} />
받는 쪽
import {useLocation} from 'react-router-dom';
const {state} = useLocation();
state.id 로 접근하면 된다.