小编Kuk*_*Bra的帖子

作为 prop 传递时,Register 不是一个函数?

我第一次使用react-hook-form。我正在阅读文档并遵循。同样,我已经布置了组件并设计了它们的样式。现在我试图在表单提交后提醒数据。

这是ContactForm

import React, { useState } from 'react';
import * as S from './style';
import { PrimaryButton } from '@element/Button';
import TextInput from '@element/TextInput';
import { useForm } from 'react-hook-form';

export const ContactForm = () => {
  const { register, handleSubmit } = useForm();
  const [firstName, setFirstName] = useState('');
  const onSubmit = (data) => {
    alert(JSON.stringify(data));
  };
return (
    <S.ContactFormWrapper onSubmit={handleSubmit(onSubmit)}>
      <TextInput
        name={'firstName'}
        label={'First Name'}
        state={firstName}
        setState={setFirstName}
        placeholder={'John'}
        type={'text'}
        width={'48%'}
        options={{
          maxLength: '20',
          minLength: '2',
          required: true,
        }} …
Run Code Online (Sandbox Code Playgroud)

forms validation styled-components next.js react-hook-form

3
推荐指数
1
解决办法
4817
查看次数