use-persisted-state | custom React Hook that provides a multi-instance | Frontend Utils library

 by   donavon JavaScript Version: 0.3.3 License: MIT

kandi X-RAY | use-persisted-state Summary

kandi X-RAY | use-persisted-state Summary

use-persisted-state is a JavaScript library typically used in User Interface, Frontend Utils, React Native, React applications. use-persisted-state has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can install using 'npm i use-persisted-state' or download it from GitHub, npm.

A custom React Hook that provides a multi-instance, multi-tab/browser shared and persistent state.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              use-persisted-state has a medium active ecosystem.
              It has 1336 star(s) with 99 fork(s). There are 9 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 21 open issues and 7 have been closed. On average issues are closed in 299 days. There are 24 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of use-persisted-state is 0.3.3

            kandi-Quality Quality

              use-persisted-state has 0 bugs and 0 code smells.

            kandi-Security Security

              use-persisted-state has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              use-persisted-state code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              use-persisted-state is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              use-persisted-state releases are not available. You will need to build from source code and install.
              Deployable package is available in npm.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of use-persisted-state
            Get all kandi verified functions for this library.

            use-persisted-state Key Features

            No Key Features are available at this moment for use-persisted-state.

            use-persisted-state Examples and Code Snippets

            No Code Snippets are available at this moment for use-persisted-state.

            Community Discussions

            Trending Discussions on use-persisted-state

            QUESTION

            Infinite loop when calling a module that uses a hook
            Asked 2021-Sep-12 at 23:22

            In Main.tsx, I have been using useApi(opts,payload), which is a hook I made that is subscribed to changes in payload. It will make an API call whenever that variable is changed.

            When I use usApi() in Main.tsx (as I have commented out), everything works fine.

            It is only when I moved this logic to another functional component (Auth.tsx), and try to call it within Main.tsx that I encounter a problem. The problem is that it seems to attempt to make an API call in an infinite loop, but never throws an error.

            What is happening here?

            Main.tsx

            ...

            ANSWER

            Answered 2021-Sep-12 at 23:22

            We've spoken a little bit on chat in order to find out a little bit more about what is going on here. I'll edit your question in a moment to take out the irrelevant code so that this is easier to understand for anyone stumbling on the question.

            Your original code did the following:

            • Instantiated an object (defaultProps) within a functional component
            • Passed that object in as the default for a useState() call
            • Passed the state value into your hook, which was then used in the dependency array of a useEffect() hook

            Your refactor changed it so you were directly passing the defaultProps reference into your hook without going through a useState() hook as before.

            An important thing to understand about React components is that although their execution pattern is somewhat predictable, it is something you have no control over as a developer and so you should assume when writing your components that they may be re-rendered at any time.

            Within a functional component, each re-render is a new function execution with a new scope. If you instantiate an object within this scope, that's a new reference variable pointing to a different area of memory each time

            The problem with then using this within the dependency array of a useEffect() hook is that since this is a new variable on each render, it means that each time the component is re-rendered, the useEffect hook will see a different reference, and cause the effect callback to be executed again. This is not normally the intended behaviour.

            Source https://stackoverflow.com/questions/69155534

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install use-persisted-state

            You can install using 'npm i use-persisted-state' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i use-persisted-state

          • CLONE
          • HTTPS

            https://github.com/donavon/use-persisted-state.git

          • CLI

            gh repo clone donavon/use-persisted-state

          • sshUrl

            git@github.com:donavon/use-persisted-state.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Frontend Utils Libraries

            styled-components

            by styled-components

            formik

            by formium

            particles.js

            by VincentGarreau

            react-redux

            by reduxjs

            docz

            by pedronauck

            Try Top Libraries by donavon

            hook-flow

            by donavonShell

            use-dark-mode

            by donavonJavaScript

            use-event-listener

            by donavonJavaScript

            thwack

            by donavonJavaScript

            undefined-is-a-function

            by donavonJavaScript