Last active
May 15, 2019 16:19
-
-
Save ryanflorence/87489cfd6d4ea0ca183cf0d09167e2e4 to your computer and use it in GitHub Desktop.
Revisions
-
ryanflorence revised this gist
May 15, 2019 . 1 changed file with 10 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,27 @@ 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> -
ryanflorence created this gist
May 15, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function RadioGroup({ onChange, name, children }) { const [state, inputProps] = useRadioGroup(name) return React.Children.map(children, child => { return React.cloneElement(child, inputProps) }) } function RadioInput(props) { return ( <label> <input {...props} /> </label> ) } function App() { return ( <RadioGroup name="snack" onChange={handleChange}> <RadioInput label="Popcorn" value="pop-corn" /> <RadioInput label="Popcorn" value="pop-corn" /> <RadioInput label="Popcorn" value="pop-corn" /> </RadioGroup> ) }