首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在不删除react index.js文件中的严格模式的情况下解决严格模式警告

如何在不删除react index.js文件中的严格模式的情况下解决严格模式警告
EN

Stack Overflow用户
提问于 2020-11-11 16:23:58
回答 1查看 135关注 0票数 0

当我以下面的形式使用<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,它仍然显示这个警告。那么我可以在不删除索引文件中的的情况下修复它吗

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2020-11-21 20:27:37

我不认为你能做到这一点。

相反,为什么不这样做(在index.js文件中):

代码语言:javascript
运行
复制
if (process.env.NODE_ENV === 'development') {
   return <React.StrictMode><App /></React.StrictMode>;
}
else
{
   return <App />;
}

您可以根据自己的意愿使用其他标志...这只是个想法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64782838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档