Last active
August 16, 2020 02:16
-
-
Save quisido/d4ced8a70b338e56e81f1bcb2403fca6 to your computer and use it in GitHub Desktop.
capsule.useState
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
// Manage a capsule with the useCapsule hook. | |
import { useCapsule } from 'react-capsule'; | |
import myCapsule from '...'; | |
export default function MyComponent() { | |
const [value, setValue] = useCapsule(myCapsule); // 💊 | |
// Change my capsule's value on click. | |
const handleClick = React.useCallback(() => { | |
setValue('your value'); | |
}, [setValue]); | |
return <button onClick={handleClick}>{value}</button>; // my initial value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment