Skip to content

Instantly share code, notes, and snippets.

@quisido
Last active August 16, 2020 02:16
Show Gist options
  • Save quisido/d4ced8a70b338e56e81f1bcb2403fca6 to your computer and use it in GitHub Desktop.
Save quisido/d4ced8a70b338e56e81f1bcb2403fca6 to your computer and use it in GitHub Desktop.
capsule.useState
// 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