Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active May 15, 2019 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/87489cfd6d4ea0ca183cf0d09167e2e4 to your computer and use it in GitHub Desktop.
Save ryanflorence/87489cfd6d4ea0ca183cf0d09167e2e4 to your computer and use it in GitHub Desktop.
function RadioGroup({ onChange, name, children }) {
const [state, inputProps] = useRadioGroup(name)
return (
<Context.Provider value={inputProps}>
{children}
</Context.Provider>
)
}
function RadioInput(props) {
const context = useContext(Context)
return (
<label>
<input {...props} {...context} />
</label>
)
}
function App() {
return (
<RadioGroup name="snack" onChange={handleChange}>
<div>
<RadioInput label="Popcorn" value="pop-corn" />
</div>
<RadioInput label="Popcorn" value="pop-corn" />
<RadioInput label="Popcorn" value="pop-corn" />
</RadioGroup>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment