React Hooks β€” πŸ‘

Related tags

React react-use
Overview



πŸ‘
react-use





npm package CircleCI master npm downloads demos
Collection of essential React Hooks. Port of libreact.
Translations: πŸ‡¨πŸ‡³ 汉语




npm i react-use












Usage β€” how to import.
Unlicense β€” public domain.
Support β€” add yourself to backer list below.






Contributors








Comments
  • The automated release is failing 🚨

    The automated release is failing 🚨

    :rotating_light: The automated release from the master branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here is some links that can help you:

    If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


    Invalid npm token.

    The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

    If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

    Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


    Good luck with your project ✨

    Your semantic-release bot :package::rocket:

    semantic-release 
    opened by streamich 24
  • Typescript 4.1.2 fails with

    Typescript 4.1.2 fails with "Cannot find name 'PositionError'"

    What is the current behavior? I've got an error

    node_modules/react-use/lib/useGeolocation.d.ts(11,21): error TS2304: Cannot find name 'PositionError'.
    

    react-use: 15.3.4 typescript: 4.1.2

    released 
    opened by syabro 16
  • Couldn't find package

    Couldn't find package "@xobotyi/[email protected]"when I executed "yarn add react-use"

    What is the current behavior? [1/4] πŸ” Resolving packages... error Couldn't find package "@xobotyi/[email protected]" required by "react-use" on the "npm" registry. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. image

    Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below: none What is the expected behavior? Install it A little about versions:

    • OS: Mac OS 10.15.6
    • Browser (vendor and version): Chrome 84.0.4147.105
    • React: 16.10.0
    • react-use: 15.3.3
    • Did this worked in the previous package version? no
    opened by Bruce-zxy 12
  • feat: improve useAsyncFn and useAsync typings

    feat: improve useAsyncFn and useAsync typings

    useAsyncFn and useAsync typings made great again =)
    Now it uses fully generic arguments and returning types, thus no problems with inferring callback arguments and value types;

    PS: @streamich check the #381 PR too.

    enhancement released 
    opened by xobotyi 12
  • useSetState doesn't work

    useSetState doesn't work

    since update to react 16.8.2 useSetState doesn't work

    https://streamich.github.io/react-use/?selectedKind=State%2FuseSetState&selectedStory=Demo&full=0&addons=1&stories=1&panelRight=0

    opened by ilovedesert001 12
  • TypeScript build fails

    TypeScript build fails

    I’ve enabled the strict option in my tsconfig.json, and installing this package results in an error because it can’t find types for the useCallbag hook, even though I don’t use that hook. It seems to be trying to import the types for the use-callbag package, which don’t exist. Can you fix this error?

    bug 
    opened by j-f1 12
  • useAsyncFn - return Promise.reject() or Promise.resolve() in the promise resolution

    useAsyncFn - return Promise.reject() or Promise.resolve() in the promise resolution

    Problem

    const [registration, register] = useAsyncFn(Service.register)
    
    async function handleSubmit(){
      try {
        await register(payload)
        // it always succeeds
      } catch(error){
        // it never reaches here
      } 
    }
    
    opened by diegoarcega 11
  • useCallback usage

    useCallback usage

    Why the get, set, remove and remove functions are not wrapped in useCallback?

    https://github.com/streamich/react-use/blob/master/src/useMap.ts

    The same question applies to functions returned by useList.

    question 
    opened by AjaxSolutions 11
  • chore: Reconfigure GitHub workflows

    chore: Reconfigure GitHub workflows

    Description

    This PR addresses https://github.com/streamich/react-use/pull/2080#pullrequestreview-743239467.

    The yaml is inspired by gicentre/prettier-plugin-elm β†’ .github/workflows/check-codebase.yml.

    Type of change

    • [ ] ~~Bug fix (non-breaking change which fixes an issue)~~
    • [ ] ~~xNew feature (non-breaking change which adds functionality)~~
    • [ ] ~~Breaking change (fix or feature that would cause existing functionality to not work as before)~~
    • [x] Chore (CI updates)

    Checklist

    • [x] Read the Contributing Guide
    • [x] Perform a code self-review
    • [x] Comment the code, particularly in hard-to-understand areas
    • [ ] ~~Add documentation~~
    • [ ] ~~Add hook's story at Storybook~~
    • [ ] ~~Cover changes with tests~~
    • [x] Ensure the test suite passes (yarn test)
    • [ ] ~~Provide 100% tests coverage~~
    • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [x] Make sure types are fine (yarn lint:types).
    released 
    opened by kachkaev 10
  • Regression: `usePrevious` prematurely updates in `StrictMode` β€” needs to `useEffect`

    Regression: `usePrevious` prematurely updates in `StrictMode` β€” needs to `useEffect`

    What is the current behavior?

    As of #1295 (v15.3.0), if React renders a component twice before committing (as it does to every component in the excellent <React.StrictMode>, and apparently as CodePen does even without StrictMode), the second render will get a prematurely updated value. The React docs (which the react-use docs references) uses useEffect for this reason. That PR should be reverted. 😞

    Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

    Use <StrictMode> to turn on double-rendering. Use usePrevious. Note that on the second render, the usePrevious value is from the first (duplicate, discarded) render, not from the previous commit. This means that, for the render which ends up getting committed, the usePrevious value that ends up reflected in the DOM is always the current one, not the previous one.

    What is the expected behavior?

    The previous value should not update until after the render is committed, via useEffect.

    A little about versions:

    • OS: n/a
    • Browser (vendor and version): n/a
    • React: n/a
    • react-use: 15.3.0
    • Did this worked in the previous package version? Yes, until #1295 and v15.3.0.
    released 
    opened by dcporter 10
  • Fix use local storage

    Fix use local storage

    Addresses #785

    Description

    Basically a total rewrite of useLocalStorage to ensure updates to the keyed value are picked up by all components watching for it.

    Type of change

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

    I don't believe this will cause any breaking changes. But I did end up tearing out almost all the old code and fundamentally changed how this hook works. πŸ€·β€β™‚

    Checklist

    • [x] Read the Contributing Guide
      • [ ] better commit message
      • [ ] squash?
    • [x] Perform a code self-review
    • [x] Comment the code, particularly in hard-to-understand areas
    • [x] Add documentation
      • no changes
    • [x] Add hook's story at Storybook
      • no changes
    • [x] Cover changes with tests
    • [x] Ensure the test suite passes (yarn test)
    • [x] Provide 100% tests coverage
    • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [x] Make sure types are fine (yarn lint:types).
      • Could use more input for proper types, like raw=true implies value=string
    released 
    opened by TylerR909 10
  • fix(useMeasure): Correct the UseMeasureRef type declaration

    fix(useMeasure): Correct the UseMeasureRef type declaration

    Description

    Fix the type error when using useMeasure

    Screen Shot 2022-12-28 at 6 50 24 PM

    Type of change

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

    Checklist

    • [x] Read the Contributing Guide
    • [x] Perform a code self-review
    • [ ] Comment the code, particularly in hard-to-understand areas
    • [ ] Add documentation
    • [ ] Add hook's story at Storybook
    • [ ] Cover changes with tests
    • [x] Ensure the test suite passes (yarn test)
    • [ ] Provide 100% tests coverage
    • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [x] Make sure types are fine (yarn lint:types).
    opened by rnike 0
  • feat: add createSharedState

    feat: add createSharedState

    Description

    A React hook that creates a globally shared state via useSyncExternalStore. It supports performance optimization through the selector function, and will only re-render when the subscribed data changes

    Type of change

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

    Checklist

    • [x] Read the Contributing Guide
    • [x] Perform a code self-review
    • [x] Comment the code, particularly in hard-to-understand areas
    • [x] Add documentation
    • [x] Add hook's story at Storybook
    • [x] Cover changes with tests
    • [x] Ensure the test suite passes (yarn test)
    • [x] Provide 100% tests coverage
    • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [x] Make sure types are fine (yarn lint:types).
    opened by IVLIU 0
  • fix(useMethods): Make returned `methods` object stable

    fix(useMethods): Make returned `methods` object stable

    Description

    Make useMethods consistent with both useState and useReducer by not updating the returned methods object reference if initialState changes after the initial render:

    The initialState argument is the state used during the initial render. In subsequent renders, it is disregarded.

    β€” reactjs.org/docs/hooks-reference.html#lazy-initial-state

    Closes #1286

    Type of change

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

    Checklist

    • [x] Read the Contributing Guide
    • [x] Perform a code self-review
    • [x] Comment the code, particularly in hard-to-understand areas
    • [ ] Add documentation
    • [ ] Add hook's story at Storybook
    • [x] Cover changes with tests
    • [x] Ensure the test suite passes (yarn test)
    • [x] Provide 100% tests coverage
    • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [x] Make sure types are fine (yarn lint:types).
    opened by danguilherme 0
  • useCustomCompareEffect should either not be called on mount, or should call depsEqual with undefined `prev` values.

    useCustomCompareEffect should either not be called on mount, or should call depsEqual with undefined `prev` values.

    What is the current behavior?

    useCustomCompareEffect does not give a chance to prevent running the effect on mount. The code says that depsEqual are not even called, as first part of !ref.current || !depsEqual(deps, ref.current) expression is falsy.

    What is the expected behavior? depsEqual should be called to allow deciding on not running the effect on mount, as for every later state change.

    A little about versions:

    • OS: Linux
    • Browser (vendor and version): Firefox
    • React: 18.2
    • react-use: 17.4.0
    • Did this worked in the previous package version?: I don't think so.
    opened by alex-kowalczyk 0
  • Use useLayoutEffect for useEvent to avoid race conditions

    Use useLayoutEffect for useEvent to avoid race conditions

    Description

    I believe that using useEffect can lead to race conditions. Since the event is subscribed asynchronously, it can be missed or use an incorrect handler. See also:

    • https://stackoverflow.com/questions/68407187/potential-bug-in-official-useinterval-example *https://stackoverflow.com/questions/74835264/avoiding-race-conditions-with-react-hooks-and-native-callbacks/74835303#74835303

    Type of change

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

    Checklist

    • [ ] Read the Contributing Guide
    • [ ] Perform a code self-review
    • [ ] Comment the code, particularly in hard-to-understand areas
    • [ ] Add documentation
    • [ ] Add hook's story at Storybook
    • [ ] Cover changes with tests
    • [ ] Ensure the test suite passes (yarn test)
    • [ ] Provide 100% tests coverage
    • [ ] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
    • [ ] Make sure types are fine (yarn lint:types).
    opened by justanotheranonymoususer 0
Releases(v17.4.0)
Owner
Vadim Dalecky
Tuna tartare with white wine; medium-rare steak with red; crème brûlée with espresso and a glass of water.
Vadim Dalecky
React Hooks β€” πŸ‘

Collaborative editing for your app. Support on Kickstarter! ?? react-use Collection of essential React Hooks. Port of libreact. Translations: ???? 汉语

Vadim Dalecky 34.9k Jan 3, 2023
βš›οΈ Hooks for fetching, caching and updating asynchronous data in React

Hooks for fetching, caching and updating asynchronous data in React Enjoy this library? Try the entire TanStack! React Table, React Form, React Charts

Tanner Linsley 32.1k Jan 9, 2023
React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name β€œSWR” is derived from stale-while-revalidate, a cache inva

Vercel 25.2k Jan 4, 2023
βš›οΈ Hooks for building fast and extendable tables and datagrids for React

Hooks for building lightweight, fast and extendable datagrids for React Enjoy this library? Try them all! React Query, React Form, React Charts Visit

Tanner Linsley 20.3k Jan 3, 2023
Fully typed hooks and utility functions for the React Native StyleSheet API

react-native-style-utilities Fully typed hooks and utility functions for the React Native StyleSheet API npm i react-native-style-utilities ESLint Set

Marc Rousavy 73 Dec 17, 2022
Redux-Toolkit example with React Hooks CRUD Application, Axios, Rest API, Bootstrap

Redux-Toolkit CRUD example with React Hooks, Axios & Web API Build Redux-Toolkit CRUD application with React Hooks and Rest API calls in that: Each it

null 69 Dec 27, 2022
Built a covid-19 trcaker app using React.js implementing hooks and materail UI

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Aditya Dond 1 Dec 21, 2021
React Hooks tutorial for beginners.

React Hooks for Beginners git clone <url> Clone into the repo code react-hooks Open the folder in VS Code npm install Install the dependencies npm sta

Mohammad Muazam 2 Oct 10, 2022
A custom ESLint rule to allow static deps in React Hooks βš›οΈ

eslint-plugin-react-hooks-static-deps A custom ESLint rule to allow static deps in React Hooks βš›οΈ Motivation react-hooks/exhaustive-deps is a really n

StoΓ―k 3 Apr 5, 2022
Add multiplayer presence (live cursors/avatars) to your react application using yjs and hooks

y-presence Easy way to add presence (live cursors/avatars) to any react application using react hooks. Installation yarn add y-presence # or npm i y-p

Nimesh Nayaju 126 Dec 29, 2022
Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality.

apollo-augmented-hooks Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional

appmotion Devs 57 Nov 18, 2022
preact.js with hooks and ES2021, without compilers

naked preact preact.js with hooks, without compilers Web development should be simple. No compilers, just ES2021 and preact+hooks. See comments in the

Oleksandr Nikitin 3 Jun 16, 2022
A library of RxJS-related hooks

rxooks GADZOOKS! RXOOKS! (Basically every other iteration of "rxjs", "rx", "react", and "hooks" was taken) This is a library of hooks that are useful

Ben Lesh 81 Nov 28, 2022
A npm package to increase the developer experience and consistency by providing a set of hooks that can be opted-in the development lifecycle.

@jeliasson/husky-hooks This npm package aims to increase the developer experience and consistency by providing a set of hooks that can be opted-in the

Johan Eliasson 8 Dec 6, 2022
Fast, tiny and solid hooks system for Javascript and Node.js

Uncino ?? Fast, tiny and solid hooks system for Javascript and NodeJS Uncino is italian word for hook Do you know Wordpress hooks system? Uncino is a

Riccardo Tartaglia 201 Dec 7, 2022
Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil Β· Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Facebook Experimental 18.2k Jan 8, 2023
React Starter Kit β€” isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit β€” "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Dec 30, 2022
:black_medium_small_square:React Move | Beautiful, data-driven animations for React

React-Move Beautiful, data-driven animations for React. Just 3.5kb (gzipped)! Documentation and Examples Features Animate HTML, SVG & React-Native Fin

Steve Hall 6.5k Jan 1, 2023
React features to enhance using Rollbar.js in React Applications

Rollbar React SDK React features to enhance using Rollbar.js in React Applications. This SDK provides a wrapper around the base Rollbar.js SDK in orde

Rollbar 39 Jan 3, 2023