【问题标题】:react js not lilting me to type in any of the input fields ( I tried to remove the value props but still not working)react js没有让我在任何输入字段中输入(我试图删除值道具但仍然无法正常工作)
【发布时间】:2021-02-02 03:45:29
【问题描述】:

我正在使用 React Js 做一个简单的联系表单,我已经使用 react bootstrap 创建了组件,但是当我尝试输入输入字段时,我根本没有改变。

import React, {useState} from 'react';
import { Container, Row, Col,Form , Button} from "react-bootstrap";
import Particle from "./Particle";
import "../style.css";
import "bootstrap/dist/css/bootstrap.min.css";

function ContactMe(){
   const [name, setname] = useState("");

function handelChange(e){
    const newName = e.target.value;
    setname(newName);
    console.log(newName);
}
return (
    <Container fluid className="about-section">
    <Particle />
    <Container>
<h1>Contact Me form </h1>

<Container className="d-flex flex-column">
<Form>
 <label>Name</label>
<Form.Control type="text" placeholder="Enter your name" onChange={handelChange} value={name}/>
<label>Email</label>
<Form.Control type="email" placeholder="Enter your Email" />
<label>Message</label>
<Form.Control as="textarea" type="text" placeholder="Enter your message" />
<Button variant="outline-danger mt-5 ">Danger</Button>

</Form>
</Container>

</Container>
</Container>
);

}

导出默认的 ContactMe;`

我已尝试删除value={name},但效果不佳

【问题讨论】:

  • 我曾尝试使用&lt;input&gt;&lt;/input&gt;,但效果不佳
  • 如果您删除onChangevalue 属性,您可以在文本字段中输入任何内容还是保持空白?

标签: javascript reactjs forms input react-bootstrap


【解决方案1】:
  1. 您为什么不使用 TextInput 组件而不是 Form.Control
  2. value 属性应该具有更新后的状态值,但您似乎正在返回状态的初始值。

也许您可以尝试为具有您需要的属性的用户创建一个原型-在这种情况下为“名称”-,并在每次提交表单时创建一个新的用户对象。

只是说出我的想法,我也是初学者。不要烤我哈哈。

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多