Created
September 12, 2021 14:45
-
-
Save callingmedic911/07ffe53217a09339c842f631c9e084ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useForm, Controller } from 'react-hook-form' | |
import Select from 'react-select/creatable' | |
export const QUERY = gql` | |
query FindPlants { | |
userExamples { | |
id | |
} | |
} | |
` | |
export const Loading = () => <div>Loading...</div> | |
export const Empty = () => <div>Empty</div> | |
export const Failure = ({ error }) => ( | |
<div style={{ color: 'red' }}>Error: {error.message}</div> | |
) | |
export const Success = ({ userExamples }) => { | |
const methods = useForm() | |
return ( | |
<form onSubmit={methods.handleSubmit((data) => console.log(data))}> | |
<Controller | |
control={methods.control} | |
defaultValue={[]} | |
name="field_name_product" | |
render={({ field }) => { | |
console.log(field) | |
const { onChange, value, name, ref } = field | |
return ( | |
<Select | |
name={name} | |
inputRef={ref} | |
options={userExamples} | |
value={userExamples.find((c) => c.id === value)} | |
onChange={(val) => { | |
onChange(val) | |
}} | |
getOptionValue={(option) => option.id} | |
getOptionLabel={(option) => option.email} | |
className="basic-multi-select" | |
classNamePrefix="select" | |
isMulti | |
/> | |
) | |
}} | |
/> | |
<button type="submit">Submit</button> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment