首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:使用useStateCallback时未实现的函数

错误:使用useStateCallback时未实现的函数
EN

Stack Overflow用户
提问于 2022-03-18 05:21:04
回答 1查看 1.1K关注 0票数 1

我正在使用react,现在我想在setState完成时做一些事情。我正在尝试使用useStateCallback来完成这个任务,这是useStateCallback定义:

代码语言:javascript
复制
  const [currentRow, setCurrentRow] = useStateCallback<API.InterviewListItem>();

currentRow是表行记录,现在当设置当前行完成时,我想做一些事情,在我的代码中,我这样做:

代码语言:javascript
复制
<a
          key="config"
          onClick={() => {
            setCurrentRow(record,(s:any) => {
              // do something when the set current row complete
            });
            handleUpdateModalVisible(true);            
          }}
        >

但是,当我编译代码时,会显示如下错误:

代码语言:javascript
复制
Error: Function not implemented.
useStateCallback
.ant-design-pro/src/pages/apps/jobs/Interview/index.tsx:402
  399 | 
  400 | export default TableList;
  401 | function useStateCallback<T>(): [any, any] {
> 402 |   throw new Error('Function not implemented.');
  403 | }
  404 | 
  405 | 
View compiled
TableList
.ant-design-pro/src/pages/apps/jobs/Interview/index.tsx:101
   98 | const [showDetail, setShowDetail] = useState<boolean>(false);
   99 | 
  100 | const actionRef = useRef<ActionType>();
> 101 | const [currentRow, setCurrentRow] = useStateCallback<API.InterviewListItem>();
      | ^  102 | const [selectedRowsState, setSelectedRows] = useState<API.InterviewListItem[]>([]);
  103 | const { initialState } = useModel('@@initialState');
  104 | 
View compiled
▶ 22 stack frames were collapsed.
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.  Click the 'X' or hit ESC to dismiss this message.

发生什么事了?我该怎么做才能修好它?我读过这个答案,然后是:How to use callback with useState hook in react

EN

回答 1

Stack Overflow用户

发布于 2022-03-18 06:00:56

我正在使用useEffect修复这个问题:

代码语言:javascript
复制
useEffect(()=>{
    console.log('Do something after current row has changed', currentRow);
    if(currentRow === undefined){
      return;
    }
    handleUpdateModalVisible(true);            
  },[currentRow]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71522770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档