vtaits / react-select-async-paginate

Wrapper above react-select that supports pagination on menu scroll
MIT License
308 stars 75 forks source link

How to use this with react-form-hook? #139

Closed yelnyafacee closed 1 year ago

yelnyafacee commented 1 year ago

Hi, How to use this with react-form-hook?

  <Controller
      name="recipients"
      control={control}
      // defaultValue={selectedValues}
      // rules={{ required: true }}
      // onChange={(inputValue) => handleChange(inputValue)}
      // onChange={handleChange} // [ Not Required in react-hook-form, auto managed by react-hook-form
      render={({ onChange, defaultValue }) => (

          <AsyncPaginate
              value={value}
              loadOptions={loadOptions2}
              onChange={onChange}
          />

      )}
  />

tried this but it does not work

vtaits commented 1 year ago

Hello. Please make a sandbox example

lamhungypl commented 1 year ago

You need to spread the value and onChange props from the fields parameter

See more in Controller's api

<Controller
  control={control}
  name="test"
  render={({
    field: { onChange, onBlur, value, name, ref },
    fieldState: { invalid, isTouched, isDirty, error },
    formState,
  }) => (
    <Checkbox
      onBlur={onBlur} // notify when input is touched
      onChange={onChange} // send value to hook form
      checked={value}
      inputRef={ref}
    />
  )}
/>
vtaits commented 1 year ago

Example added to README

https://codesandbox.io/s/x7vw8c