Reactjs 财产';细节';不存在于类型';{}';。ts(2339)
我在下面的代码中得到了标题中的错误,如何修复它Reactjs 财产';细节';不存在于类型';{}';。ts(2339),reactjs,typescript,react-hooks,tsx,react-tsx,Reactjs,Typescript,React Hooks,Tsx,React Tsx,我在下面的代码中得到了标题中的错误,如何修复它 感谢您的帮助 欢迎来到StackOverflow 代码的问题在于位置的状态部分是用户定义的。因此,假设您知道在状态中填充了什么,您需要做的是指定您所拥有的状态类型: interface State { detail: string; } const location = useLocation<State>(); useEffect(() => { console.log(location.state.det
- 感谢您的帮助李>
欢迎来到StackOverflow 代码的问题在于位置的
状态
部分是用户定义的。因此,假设您知道在状态中填充了什么,您需要做的是指定您所拥有的状态类型:
interface State {
detail: string;
}
const location = useLocation<State>();
useEffect(() => {
console.log(location.state.detail);
}, [location]);
接口状态{
细节:字符串;
}
const location=useLocation();
useffect(()=>{
日志(location.state.detail);
},[地点];
//otherPage
import React, { useEffect } from 'react';
import { useLocation } from "react-router-dom";
const location = useLocation();
useEffect(() => {
console.log(location.state.detail);
}, [location]);
interface State {
detail: string;
}
const location = useLocation<State>();
useEffect(() => {
console.log(location.state.detail);
}, [location]);