Reactjs 表单提交已取消,因为表单未连接-控制台错误

Reactjs 表单提交已取消,因为表单未连接-控制台错误,reactjs,react-hooks,use-state,Reactjs,React Hooks,Use State,我已经在网上搜索过了,但是仍然找不到为什么我的表格没有提交,但是它在前端显示了数据。我正在使用钩子从表单中获取数据。有没有更好或更干净的代码行?短暂性脑缺血发作 这是控制台错误,我得到=>表单提交被取消,因为表单未连接 这是我的AddUser.js import {Form,FormGroup,Label,Input,Button} from 'reactstrap'; import{GlobalContext} from '../context/GlobalState'; import {Li

我已经在网上搜索过了,但是仍然找不到为什么我的表格没有提交,但是它在前端显示了数据。我正在使用钩子从表单中获取数据。有没有更好或更干净的代码行?短暂性脑缺血发作

这是控制台错误,我得到=>表单提交被取消,因为表单未连接

这是我的AddUser.js

import {Form,FormGroup,Label,Input,Button} from 'reactstrap';
import{GlobalContext} from '../context/GlobalState';
import {Link, useHistory} from 'react-router-dom';
import {v4 as uuid} from 'uuid';


export const AddUser = () => {

  const {addEmployee } = useContext(GlobalContext);
  const [name, setName] = useState('');
  const [nameL,setNameL] = useState('');
  const [email,setEmail] = useState('');
  const [contact,setContact] = useState('');
  const [address,setAddress] = useState('');
  const [date,setDate] = useState('');

  const history= useHistory();

  const onChange = (e) =>{
      setName(e.target.value);
 
  }
  const onNameL = (e) =>{
 
      setNameL(e.target.value);
     
  }
  const onEmail = (e) =>{
      setEmail(e.target.value);
 
  }
  const onContact = (e) =>{
      setContact(e.target.value);
 
  }
  const onAddress = (e) =>{
      setAddress(e.target.value);
 
  }
  const onDate = (e) =>{
      setDate(e.target.value);
 
  }
  const onSubmit= () =>{
      
      const newEmployee = {
          id: uuid(),
          name,nameL,email,contact,address,date
      }
      
      addEmployee(newEmployee);
      
      history.push('/');

  }

  return (
      <React.Fragment>
          <Form onSubmit={onSubmit}>
              <FormGroup >
                  
                  <Label>First Name:</Label>
                  <Input type="text" value= {name}  onChange={onChange} placeholder="enter your First name"></Input>
                  <Label>Last Name:</Label>
                  <Input type="text"value= {nameL}  onChange={onNameL} placeholder="enter your Last name"></Input>
                  <Label>Email:</Label>
                  <Input type="email"value= {email}  onChange={onEmail} placeholder="Email Address"></Input>
                  <Label>Contact Number:</Label>
                  <Input type="number"value= {contact}  onChange={onContact} placeholder="Contact"></Input>
                  <Label>Address:</Label>
                  <Input type="text"value= {address}  onChange={onAddress} placeholder="enter your Address"></Input>
                  <Label>Enter Date of Employment:</Label>
                  <Input type="date"value= {date}  onChange={onDate} placeholder="enter date employed"></Input>
              </FormGroup>
              <Button type="submit" className="btn btn-success">Submit</Button>
              <Link to="/" className="btn btn-danger">Cancel</Link>
          </Form>
      </React.Fragment>
  )
}
export default AddUser`` 





import{Form,FormGroup,Label,Input,Button}来自'reactstrap';
从“../context/GlobalState”导入{GlobalContext};
从“react router dom”导入{Link,useHistory};
从“uuid”导入{v4 asuuid};
导出常量AddUser=()=>{
const{addEmployee}=useContext(GlobalContext);
const[name,setName]=useState(“”);
const[nameL,setNameL]=useState(“”);
const[email,setEmail]=useState(“”);
const[contact,setContact]=useState(“”);
const[address,setAddress]=useState(“”);
const[date,setDate]=使用状态(“”);
const history=useHistory();
const onChange=(e)=>{
设置名称(如目标值);
}
const onNameL=(e)=>{
setNameL(即目标值);
}
const onEmail=(e)=>{
setEmail(例如target.value);
}
const onContact=(e)=>{
设置触点(如目标值);
}
const onAddress=(e)=>{
设置地址(如目标值);
}
const onDate=(e)=>{
设置日期(如目标值);
}
const onSubmit=()=>{
const newEmployee={
id:uuid(),
姓名、姓名、电子邮件、联系人、地址、日期
}
新增员工(新员工);
历史推送(“/”);
}
返回(
名字:
姓氏:
电邮:
联络电话:
地址:
输入雇用日期:
提交
取消
)
}
导出默认的AddUser`

我只是将按钮类型更改为button而不是submit,它就可以工作了


Submit

GlobalState的代码是什么?
const addEmployee=(user)=>{dispatch({type:'ADD_EMPLOYEE',payload:user})
而这是来自reducer:
case'ADD_EMPLOYEE':return{users:[action.payload,…state.users]}