Jonatha Rihan
Jonatha Rihan

Reputation: 89

React Native React-Hook-Form Reset

how can I reset/clear <S.Input /> field, I'm using react-hook-form and Typescript.

Code:

  const {register, handleSubmit, setValue, errors} = useForm();

  useEffect(() => {
    register('content')
  }, [register]);

  return(

      <S.Input
        onChangeText={text => {setValue('content', text)}}
        multiline
        textAlignVertical="top"
        maxLength={280}
        placeholder="O que está pensando?"
        selectTextOnFocus={true}
      />
      <S.Button disabled={isLoading} onPress={handleSubmit(handlePost)} />

Upvotes: 0

Views: 642

Answers (1)

nipuna-g
nipuna-g

Reputation: 6652

You can setValue to the default value since the component is not a controlled one or wrapped in the Controller.

Wrapping the input in a controller would allow you to use reset. https://react-hook-form.com/api/#reset

const {register, handleSubmit, setValue, errors} = useForm();

// to reset the input
setValue({content: '})

Upvotes: 1

Related Questions