Reactjs 使用useState根据设定值对火灾事件或火灾方法作出反应
对于以这种方式定义的变量:Reactjs 使用useState根据设定值对火灾事件或火灾方法作出反应,reactjs,use-state,Reactjs,Use State,对于以这种方式定义的变量: const [voivodeshipDict, setVoivodeshipDictValues] = useState<IDictionary[]>([] as IDictionary[]); const[voivodeshipDict,setVoivodeshipDictValues]=useState([]作为IDictionary[]); 对于每个调用“setVoivodeshipDictValues”,我希望在设置值后触发其他代码。实施这一点
const [voivodeshipDict, setVoivodeshipDictValues] = useState<IDictionary[]>([] as IDictionary[]);
const[voivodeshipDict,setVoivodeshipDictValues]=useState([]作为IDictionary[]);
对于每个调用“setVoivodeshipDictValues”,我希望在设置值后触发其他代码。实施这一点很热吗
对不起,我说的是英语。我想你在找
useffect()
hook:
useEffect(() => {
// Do stuffs whenever voivodeshipDict is changed
}, [voivodeshipDict])
我想您正在寻找
useffect()
hook:
useEffect(() => {
// Do stuffs whenever voivodeshipDict is changed
}, [voivodeshipDict])
我认为您可以在依赖项数组中使用useeffect钩子和“voivodeshipDict”,并将要运行的代码放在其中。我认为您可以在依赖项数组中使用useeffect钩子和“voivodeshipDict”,并将要运行的代码放在其中