Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get a warning when use rc-form-hooks #74

Open
FurryWolfX opened this issue Sep 15, 2021 · 0 comments
Open

get a warning when use rc-form-hooks #74

FurryWolfX opened this issue Sep 15, 2021 · 0 comments

Comments

@FurryWolfX
Copy link

Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.

function RcForm() {
  const { getFieldDecorator, validateFields, errors, values } = useForm<{
    username: string;
  }>();

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    validateFields()
      .then(console.log)
      .catch(e => console.error(e.message));
  };

  return (
    <form onSubmit={handleSubmit}>
      {getFieldDecorator('username', {
        rules: [{ required: true, message: 'Please input username!' }]
      })(<input type='text' />)}
      <span style={{color: 'red'}}>{values.username}</span>
      {errors.username && <span style={{color: 'blue'}}>{errors.username[0].message}</span>}
      <button type={'submit'}>submit</button>
    </form>
  )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant