我第一次尝试使用react-hook-form
(https://react-hook-form.com/ )。我不知道如何用 redux 将它们组合成 react 组件。
import React from 'react'
import useForm from 'react-hook-form'
export default function SampleForm() {
const { register, handleSubmit, watch, errors } = useForm()
const onSubmit = data => { console.log(data) }
console.log(watch('example')) // watch input value by passing the name of it
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="example" defaultValue="test" ref={register} />
<input name="exampleRequired" ref={register({ required: true })} />
{errors.exampleRequired && <span>This field is required</span>}
<input type="submit" />
</form>
);
}
import React, { Component } from "react";
import { connect } from "react-redux";
import userForm from 'react-hook-form';
import SampleForm from "./SampleForm";
class Sample extends Component {
constructor(props){
super(props);
}
render() {
return (
<SampleForm />
);
}
}
export default connect()(Sample);
有人帮助我吗?