![](/img/trans.png)
[英]Fixing 'index.js:1 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code' in react
[英]How can I solve strict mode warning without removing strict mode in react index.js file
当我在下面的表格中使用<Button />
时,它会说
Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of RefFindNode which is inside StrictMode. Instead, add a ref directly to the element you want to reference.
即使我使用了 useRef,它仍然显示此警告。 那么我可以在不删除索引文件中的 <React.StrictMode></React.StrictMode> 的情况下修复它吗
import React, {useRef} from 'react'
import { Button, Container, Form, Input } from 'semantic-ui-react'
import Layout from '../layout/Layout'
const Login = () => {
let btn = useRef(null)
React.useEffect(() => {
console.log(btn);
})
return (
<Layout>
<Container className="auth-form segment">
<Form>
<Form.Field
label="Email"
control={Input}
placeholder="example@gmail.com"
name="email"
/>
<Form.Field
label="Password"
control={Input}
placeholder="Password"
name="password"
type="password"
/>
<Button content="Login" ref={btn} primary/>
</Form>
</Container>
</Layout>
)
}
export default Login
我认为你做不到。
相反,你为什么不做类似的事情(在 index.js 文件中):
if (process.env.NODE_ENV === 'development') {
return <React.StrictMode><App /></React.StrictMode>;
}
else
{
return <App />;
}
您可以根据需要使用其他标志......只是一个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.