We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toggler
A useful toggler helper that returns 3 events and a store
export const toggler = (defaultValue = false): TogglerInstance => { const open = createEvent(); const close = createEvent(); const toggle = createEvent(); const $isOpen = createStore(defaultValue) .on(open, () => true) .on(close, () => false) .on(toggle, (v) => !v); return { open, close, toggle, $isOpen, }; };
export const toggler = toggler(); sample({ clock: smthEvent, target: toggler.open }}
In components it would look like this:
import { useUnit } from 'effector-react'; export function useToggler(togglerInstance: TogglerInstance) { const { $isOpen, open, close, toggle } = togglerInstance; return useUnit({ isOpen: $isOpen, open, close, toggle }); }
const { isOpen, open, close, toggle } = useToggler(someModel.toggler); <button onClick={open}>Button</button>
The text was updated successfully, but these errors were encountered:
Looks like @@unitShape can be used instead of useToggler
@@unitShape
useToggler
Sorry, something went wrong.
I propose a better name in the effector system: createToggle.
createToggle
I like)
No branches or pull requests
A useful toggler helper that returns 3 events and a store
In components it would look like this:
The text was updated successfully, but these errors were encountered: