How to use npm pkg components like react-country-region-selector with react-hook-form #7385
-
Using React, Mui5, & v7 of react-hook-form I'm using "react-country-region-selector" npm package for a country & region drop down selection. I'm unable to figure out how to use them within React-hook-form. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
can you share a codesandbox? this should be able to solve with |
Beta Was this translation helpful? Give feedback.
-
https://codesandbox.io/s/adoring-forest-5lbmr?file=/src/App.js import { CountryDropdown } from "react-country-region-selector";
import { useForm, Controller } from "react-hook-form";
import "./styles.css";
export default function App() {
const { control, handleSubmit } = useForm({
defaultValues: {
test: ""
}
});
return (
<form
onSubmit={handleSubmit((data) => {
console.log(data);
})}
>
<Controller
name="test"
render={({ field: { name, onChange, value } }) => (
<CountryDropdown
defaultOptionLabel="Select Country"
name={name}
value={value}
onChange={onChange}
/>
)}
control={control}
/>
<button>submit</button>
</form>
);
} |
Beta Was this translation helpful? Give feedback.
https://codesandbox.io/s/adoring-forest-5lbmr?file=/src/App.js