import { createContext, useContext } from 'react' import { Radio } from 'lib/ui/RadioField/Radio.js' interface RadioFieldProps { name: string value: Value onChange: (value: Value) => void options: Array> } interface RadioOption { label: string value: Value } type RadioFieldContext = Omit< RadioFieldProps, 'options' > | null const radioFieldContext = createContext>(null) export function RadioField({ value, onChange, name, options, }: RadioFieldProps): JSX.Element { const { Provider } = radioFieldContext return (
{options.map(({ value, label }, index) => ( ))}
) } export function useRadioField(): NonNullable< RadioFieldContext > { const context = useContext>(radioFieldContext) if (context === null) { throw new Error('useRadioField must be used within a ') } return context }