onchange事件处理程序的刷新问题

mznpcxlj  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(409)

我有一个带有onchange事件处理程序的输入,每当我尝试在其中键入字符时,它都会刷新屏幕。我想知道你们是否能帮我解决这个问题。
这是我的密码:

const HeaderUser: React.FC<TabWrapper> = () => {
const [drawerEmpreendimentosVisible, setDrawerEmpreendimentosVisible] = useState(false);
const intl = useIntl().formatMessage;
const [currentEmpreendimento] = useLocalStorage().createState('currentEmpreendimento');

const [displayRoadmapScreen, setDisplayRoadmapScreen] = useState(false)
const [displayRegisterScreen, setDisplayRegisterScreen] = useState(false);
const [inspector, setInspector] = useState('');
const [roadmap, setRoadmap] = useState('');

const RegisterScreen = () => {

    const handleOk = () => {
        setDisplayRegisterScreen(false);
    };

    const handleCancel = () => {
        setDisplayRegisterScreen(false);
    };

    return (
        <div>
           <Modal
                title="Cadastrar novo roteiro"
                visible={displayRegisterScreen}
               onOk={handleOk}
                onCancel={handleCancel}>
                <b>Roteiro:</b>
                <br />
        //Refreshing issue  <Input type="text"  placeholder="Roteiro"  onChange={e => 
                  setRoadmap(e.target.value)} /><br />
                <b>Inspetor:</b>
                <br />
                <Input type="text" name="inspector" placeholder="Inspetor"  onChange={(e) => console.log(e.target.value)} />
            </Modal>
        </div>
    )
};
wgxvkvu9

wgxvkvu91#

可能是因为您在registerscreen组件之外定义了自己的状态?尝试在组件中定义它。

const RegisterScreen = () => {

    const [roadmap, setRoadmap] = useState('');
    //rest of code...

相关问题