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,它仍然显示此警告。那么我可以在不删除索引文件中的 <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
4

1 回答 1

0

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

相反,你为什么不做类似的事情(在 index.js 文件中):

if (process.env.NODE_ENV === 'development') {
   return <React.StrictMode><App /></React.StrictMode>;
}
else
{
   return <App />;
}

您可以根据需要使用其他标志...只是一个想法。

于 2020-11-21T12:27:36.640 回答