[useToggle] Rewrite as a wrapper hook
See original GitHub issueMotivation
While the current implementation of useToggle
handles a given state variable specially, wrapper syntax would allow it to control custom states (e.g. the one returned by useLocalStorage
).
Basic example
function Example() {
const [isPressed, togglePressed] = useToggle(useLocalStorage('isPressed', false));
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Toggle state on and off with React Hooks - Josh W Comeau
This hook uses React.useCallback in order to preserve the reference to the setter function; without this wrapper, the toggle function would ...
Read more >useToggle React Hook - useHooks
Hooks are a feature in React that allow you use state and other React features without writing classes. This website provides easy to...
Read more >Custom react hook useToggle in Typescript - Stack Overflow
You might need to define the return type of your hook. It should look something like this. import { useState } from 'react';...
Read more >Creating Custom React Hooks — useToggle | by Irmak Esin
A custom hook is a Javascript function that starts with “use” and that can call other hooks. The main reason to create a...
Read more >kodingdotninja/use-toggle - GitHub
Toggle custom hook and component wrapper for React - GitHub - kodingdotninja/use-toggle: Toggle custom hook and component wrapper for React.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Jfelix61 Thanks for your contribution! If you need any kind of assistance, I’m glad to help.
This has been resolved by #78.
@Jfelix61 If you ever decide to contribute again, please refer the corresponding issue (e.g. this one) in your pull request using keywords if possible. Thank you for your efforts!