React Hook 在既不是 React 函数组件也不是自定义 React Hook 函数的函数中调用
我收到以下 ESLint 警告:
React Hook“useBuilderFeatureFlagContext”在函数“Slide.RenderBuilder”中调用,该函数既不是 React 函数组件,也不是自定义 React Hook 函数。
这是以下组件:
Slide.RenderBuilder = ({ children }) => {
const flags = useBuilderFeatureFlagContext();
return (
<>
<SlideWrapper $flags={flags}>
{children}
</SlideWrapper>
<ImageSetter attributeName="containerBackgroundImage" />
</>
);
};
如何编写可以将这种特定情况列入白名单的规则?
I have this following ESLint warning :
React Hook "useBuilderFeatureFlagContext" is called in function "Slide.RenderBuilder" that is neither a React function component nor a custom React Hook function.
and this is the following component :
Slide.RenderBuilder = ({ children }) => {
const flags = useBuilderFeatureFlagContext();
return (
<>
<SlideWrapper $flags={flags}>
{children}
</SlideWrapper>
<ImageSetter attributeName="containerBackgroundImage" />
</>
);
};
How do I write a rule that can whitelist this specific case ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果可以的话,首先定义组件,然后将其添加到您的对象中。
这样,规则就可以正确检查钩子,并且您就拥有了所需的结构。
确保将其用作组件
,否则您可能最终会违反钩子规则。If you can, define the component first, then add it to your object.
That way, the rule properly check for hooks, and you have the structure you're looking for.
Make sure to use it as a component
<Slide.RenderBuilder />
otherwise you might end up breaking rules of hooks.