itszeeshan/react-custom-hooks

Repository files navigation

Enhance your development workflow with this VS Code extension that offers a collection of useful React Custom hooks as code. Whether you're using JavaScript or TypeScript, this extension dynamically loads and provides snippets from external files, to fit your project needs.

  • Hooks Snippets: Provides ready-to-use snippets for various React hooks.
  • Automatic Loading: Loads snippets from files, including hooks that depend on others.
  • File Type Detection: Chooses the right snippet based on whether you're using JavaScript or TypeScript.
  • .js
  • .ts
  • .jsx
  • .tsx
  1. Go to VSCode extensions section.
  2. Search for react custom hooks, make sure the author is zeesec.
  3. Press Install button.
  1. Open a JavaScript or TypeScript file in VS Code.
  2. Type the snippet prefix (e.g., useFetch).
  3. Select the snippet from the suggestion list to insert it into your code.

Manual

Javascript Support With Javascript code

Typescript Support With Typescript code

Here are some of the snippets you can use:

HookDescription
useFetchA hook to fetch data from a URL.
useAsyncA hook to handle asynchronous tasks.
useArrayA hook for managing and manipulating an array with functions like push, filter, update, remove, and clear.
useClickOutsideA hook to detect clicks outside a specified element and trigger a callback.
useCookieA hook for managing cookies with get, set, and delete functionality.
useCopyToClipboardA hook to copy text to the clipboard and track success.
useDebounceA hook to debounce a callback function with a specified delay.
useDeepCompareEffectA hook for running an effect with dependencies that are deeply compared.
useEffectOnceA hook to run an effect only once on mount.
useGeolocationA hook to get and watch the user's geolocation.
useHoverA hook to track whether an element is being hovered over.
useMediaQueryA hook to detect whether a media query matches.
useOnlineStatusA hook to detect the online/offline status of the browser.
useOnScreenA hook to detect if an element is visible within the viewport.
usePreviousA hook to keep track of the previous value of a state or prop.
useRenderCountA hook to count the number of times a component has rendered.
useScriptA hook to dynamically load a script and handle its loading state.
useStorageA generic hook for managing state with a storage mechanism (e.g., localStorage, sessionStorage).
useSessionStorageA hook for managing state with sessionStorage.
useLocalStorageA hook for managing state with localStorage.
useDarkModeA hook to manage dark mode state and apply dark mode styling based on user preference and localStorage.
useTimeoutA hook to manage a timeout with set, clear, and reset functionalities.
useToggleA hook to toggle a boolean value.
useUpdateEffectA hook to run an effect only on updates, not on the initial mount.
useWindowSizeA hook to track the window size and update on resize events.
useStateWithHistoryA hook to manage state with an undo/redo history mechanism.
useStateWithValidationA hook to manage state with validation, providing validity status.
useLongPressA hook to detect long press interactions on an element.
useDebugInformationA hook to provide debugging information, including render count and changed props.
useEventListenerA hook to add an event listener to a specified element and clean up on unmount.

For detailed information about each hook, check out the following links:

Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements.

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes and test them.
  4. Submit a pull request.

This project is licensed under the MIT License. Check the LICENSE file for details.