Skip to content
Discussion options

You must be logged in to vote

Sure. In our case the SomeDropdown only accepts strings so we just convert the selectedItem to string and back to number like so:

type MyForm = {
  selectedItem: number;
}

type CustomDropdownProps = {
  control: Control<MyForm>;
}

export function CustomDropdown(): React.ReactElement {
  const {field} = useController({control: props.control, name: 'selectedItem'});
  
  function onChange(value: string) {
	field.onChange(parseInt(value, 10));
  }

  return <SomeDropdown selected={field.value.toString()} onChange={onChange}/>
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@twisted1919
Comment options

@tparvi
Comment options

Answer selected by twisted1919
@twisted1919
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants