![](/img/trans.png)
[英]Is there an implementation of infinite scroll with useEffect that doesn't trigger the react-hooks/exhaustive-deps lint warning?
[英]typescript es-lint error: react-hooks/exhaustive-deps
我最初认为这是一个误报,但直到现在我不知道为什么这个错误是有用的。
当您的外部道具 function 用于useEffect
时,如何理解react-hooks/exhaustive-deps
错误不需要依赖?
interface props {
someExternalPropFunction: any;
}
const App: React.FC<props> = ({ someExternalPropFunction }) => {
const [formValues, setFormValues] = React.useState<initialStateProps>({
eventInfo: {
name: "",
location: ""
}
});
React.useEffect(() => {
someExternalPropFunction(formValues);
}, [formValues]); //what is going on here?
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
</div>
);
};
dep 列表需要someExternalPropFunction
因为道具可能会改变。
React.useEffect(() => {
someExternalPropFunction(formValues);
}, [someExternalPropFunction, formValues]); // now it is fixed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.