React Material-UI文本字段屏幕抖动

时间:2019-09-11 05:21:44

标签: javascript reactjs material-ui

我有一个简单的反应代码。有一个material-ui文本字段。

当我在文本框中单击以输入数据时,屏幕会抖动。输入完数据后,请单击外部,然后在框上晃动屏幕。请帮我解决此屏幕抖动问题。非常感谢。

import Grid from '@material-ui/core/Grid';
import TextField from '@material-ui/core/TextField';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
const Login = props => {

    return (
        <div>
            <Grid container spacing={2} justify="center">

                <Grid item xs={12} container justify="center" spacing={2}>
                    <Grid item xs={3}>
                        <TextField
                            label="fd"
                            variant="outlined"
                            fullWidth
                        >
                        </TextField>
                    </Grid>
                </Grid>
            </Grid>

        </div>
    )
}

export default Login;

1 个答案:

答案 0 :(得分:0)

只需如下设置文本字段的onChange属性,抖动就会消失。

import React, { useState } from 'react';
import Grid from '@material-ui/core/Grid';
import TextField from '@material-ui/core/TextField';
import PropTypes from 'prop-types';
import React, { useState } from 'react';

const Login = props => {
    const [name,setName] = useState("")

    return (
        <div>
            <Grid container spacing={2} justify="center">
               <Grid item xs={12} container justify="center" spacing={2}>
                    <Grid item xs={3}>
                        <TextField
                            label="fd"
                            variant="outlined"
                            fullWidth
                            onChange={e => setName(e.target.value)}
                        />
                    </Grid>
                </Grid>
            </Grid>
        </div>
    )
}

export default Login;