快速查看我正在嘗試做的事情:import React, { useState, useEffect } from 'react';const MainComponent = () => { const [element, setElement] = useState([]); const [setThings] = useSomething(); useEffect(() => { setThings(element); }, [element]);};const useSomething = () => { const [things, setThings] = useState([]); // do stuff now that you've received things return [setThings];};以及另一個文件中的另一個鉤子。這工作得很好,并且是在 ReactJS 中使用畫布的絕佳解決方案。我有一個警告被拋出,我似乎無法通過我的研究來解決它: Line 150:7: React Hook useEffect has a missing dependency: 'setThings'. Either include it or remove the dependency array react-hooks/exhaustive-deps在反應文檔中,它說這會導致問題,因為它正在調用具有依賴性的東西,但我不知道它們在哪里?
如何在另一個組件 useEffect 中設置 State?
躍然一笑
2023-09-28 16:18:59