我只想在更改时在我的useEffect
方法中执行代码productType
,并且一旦加载页面,我就可以识别 console.log 执行超过 6-7 次,这是我不想要的。
这是我的代码的摘要:
const [productType, setProductType] = useState(null);
useEffect(() => {
console.log(productType);
}, productType);
想法是在更改useEffect
时执行代码productType
,我在下拉列表中更改它,如下所示:
<MyDropdownComponent
value={productType}
onChange={e => setExportType(e.target.value)}
width={200}
/>
所以我想知道为什么当我加载这个视图/模板时,我的控制台中出现了 6-7-8console.logs
之类的null
......