[英]Cannot read property 'firstname' of null in Reactjs
I am trying to getting data from a form using react hook useState.我正在尝试使用 react hook useState 从表单中获取数据。 But I'm facing the error
Cannot read property 'firstname' of null
while getting the value of input fields.但是我在获取输入字段的值时遇到错误
Cannot read property 'firstname' of null
。 Following is my registration and hook file.以下是我的注册和钩子文件。 registration.js
注册.js
import React from 'react';
import {
Container, Col, Form,
FormGroup, Label, Input,
Button,
} from 'reactstrap';
import useRegistrationForm from './hooks';
const Registration = () => {
const register = () => {
alert(`User Created!
Name: ${inputs.firstName} ${inputs.lastName}
Email: ${inputs.email}`);
}
const { inputs, handleInputChange, handleSubmit } = useRegistrationForm(register);
return (
<div>
<Container className="container">
<h2>Registration</h2>
<Form onSubmit={handleSubmit} className="form">
<Col>
<FormGroup>
<Label className="label"> First Name</Label>
<Input type="text" name="firstname" id="examplename" placeholder="Enter First Name"
onChange={handleInputChange} value={inputs.firstname}required></Input>
</FormGroup>
</Col>
<Button>Submit</Button>
</Form>
</Container>
</div>
)
}
export default Registration
In alert, you are using inputs.firstName
.在警报中,您正在使用
inputs.firstName
。 Could it be the reason?这可能是原因吗?
instead of firstname
>> firstName
而不是
firstname
>> firstName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.