이전 react-router-dom v5에서는 제네릭을 지원하였기 때문에
interface를 만들어서 제네릭으로 명시해주면 ts가 동작
interface RouterState {
name: string;
}
function Coin() {
const location = useLocation<RouterState>()
interface RouterState {
name: string;
}
function Coin() {
const location = useLocation()
const name=location.state as RouterState
또는
interface RouterState {
state: {
name: string;
};
}
function Coin() {
const { state } = useLocation() as RouterState;