noRenderReturnValue
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noRenderReturnValue¥Diagnostic Category:
lint/correctness/noRenderReturnValue -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
¥How to configure
{ "linter": { "rules": { "correctness": { "noRenderReturnValue": "error" } } }}¥Description
防止使用 React.render 的返回值。
¥Prevent the usage of the return value of React.render.
ReactDOM.render()当前返回对根ReactComponent实例的引用。但是,使用此返回值是遗留的,应该避免,因为 React 的未来版本在某些情况下可能会异步渲染组件。如果你需要对根ReactComponent实例的引用,则首选解决方案是将 回调引用 附加到根元素。¥
ReactDOM.render()currently returns a reference to the rootReactComponentinstance. However, using this return value is legacy and should be avoided because future versions of React may render components asynchronously in some cases. If you need a reference to the rootReactComponentinstance, the preferred solution is to attach a callback ref to the root element.
来源:ReactDOM 文档
¥Source: ReactDOM documentation
¥Examples
¥Invalid
const foo = ReactDOM.render(<div />, document.body);code-block.jsx:1:13 lint/correctness/noRenderReturnValue ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not depend on the value returned by the function ReactDOM.render().
> 1 │ const foo = ReactDOM.render(<div />, document.body);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The returned value is legacy and future versions of React might return that value asynchronously.
Check the React documentation for more information.
¥Valid
ReactDOM.render(<div />, document.body);¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号