Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created December 14, 2021 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanbsmith/2c8cc2ff54578d827ef7a7705ed6e307 to your computer and use it in GitHub Desktop.
Save alanbsmith/2c8cc2ff54578d827ef7a7705ed6e307 to your computer and use it in GitHub Desktop.
Simplified guard and callback example
const MyToggleButton = ({ isContentReady, {...props} }) => {
const modelConfig = {
isIntiallyToggled: true,
shouldToggle: (data, state) => {
if (!iContentReady) {
return false;
}
return true;
},
onToggle: (data, prevState) => {
console.log('toggled!');
}
}
const toggleButtonModel = useToggleButtonModel(modelConfig);
return <ToggleButton model={toggleButtonModel} {...props} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment