Created
December 30, 2022 23:18
-
-
Save kivircik-parantez/f34df2ba3582ad43a5751e4a2f8fd376 to your computer and use it in GitHub Desktop.
Component is fully controlled by its parent
This file contains 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 characters
// ✅ Also good: the component is fully controlled by its parent | |
function Toggle({ isOn, onChange }) { | |
function handleClick() { | |
onChange(!isOn); | |
} | |
function handleDragEnd(e) { | |
if (isCloserToRightEdge(e)) { | |
onChange(true); | |
} else { | |
onChange(false); | |
} | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment