Skip to content

Commit

Permalink
abstract radioState and setRadioState for cleaner deps
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Nov 21, 2022
1 parent 1246386 commit e184c9c
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function UnforwardedToggleGroupControlAsRadioGroup(
}, [ radio.state, previousValue, onChange ] );

// Sync incoming value with radio.state.
const { state: radioState, setState: setRadioState } = radio;
useUpdateEffect( () => {
if ( value !== radio.state ) {
radio.setState( value );
if ( value !== radioState ) {
setRadioState( value );
}
// disable reason: Adding `radio` to the dependency array causes an extra render.
// Memoizing it doesn't look easily doable, so we're disabling the rule for now.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ value ] );
// setRadioState needs to be listed even if in theory it's supposed to be a
// stable reference — that's an ESLint limitation.
}, [ value, radioState, setRadioState ] );

return (
<ToggleGroupControlContext.Provider
Expand Down

0 comments on commit e184c9c

Please sign in to comment.