reactjs - Hata: useStateCallback kullanırken Fonksiyon uygulanmadı


React useState kullanıyorum, şimdi setState tamamlandığında bir şey yapmak istiyorum. Bunu yapmak için useStateCallback kullanmayı deniyorum, işte useStateCallback tanımı:

  const [currentRow, setCurrentRow] = useStateCallback<API.InterviewListItem>();

currentRow tablo satırı kaydıdır, şimdi current row ayarlandığında bir şeyler yapmak istiyorum, kodumda bunu şöyle yapıyorum:

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

ama kodu derlediğimde, bu şekilde bir hata gösteriyor:

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.

Ne oldu? Bunu düzeltmek için ne yapmalıyım? Bu cevabı okudum ve bunu takip ettim: React'te useState kancası ile callback nasıl kullanılır

Cevap #1

Bunu düzeltmek için useEffect'i kullanıyorum:

useEffect(()=>{
    console.log('Do something after current row has changed', currentRow);
    if(currentRow === undefined){
      return;
    }
    handleUpdateModalVisible(true);            
  },[currentRow]);