React useHistory, Object is of type 'unknown'

使用React useHistory时遇到错误:Object is of type 'unknown',请大佬指教。

项目版本信息如下:

Node version: v12.14.1
React version: 17.0.1
react-router-dom version: 16.9.8
@types of react-router-dome version: ^5.1.6

使用过程

import { useHistory } from "react-router-dom";
const history = useHistory();

useEffect(() => {
    if (history.location.state) {
      const taskId: any = history.location.state.taskId
      getItemList(taskId)
    }
  }, [])

// Error message


  Object is of type 'unknown'.  TS2571

    252 |   useEffect(() => {
    253 |     if (history.location.state) {
  > 254 |       const taskId: any = history.location.state.taskId
        |                           ^
    257 |     }
阅读 5.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题