我正在使用react,现在我想在setState完成时做一些事情。我正在尝试使用useStateCallback来完成这个任务,这是useStateCallback定义:
const [currentRow, setCurrentRow] = useStateCallback<API.InterviewListItem>();currentRow是表行记录,现在当设置当前行完成时,我想做一些事情,在我的代码中,我这样做:
<a
key="config"
onClick={() => {
setCurrentRow(record,(s:any) => {
// do something when the set current row complete
});
handleUpdateModalVisible(true);
}}
>但是,当我编译代码时,会显示如下错误:
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
发布于 2022-03-18 06:00:56
我正在使用useEffect修复这个问题:
useEffect(()=>{
console.log('Do something after current row has changed', currentRow);
if(currentRow === undefined){
return;
}
handleUpdateModalVisible(true);
},[currentRow]);https://stackoverflow.com/questions/71522770
复制相似问题