Giter VIP home page Giter VIP logo

persistence-hooks's People

Contributors

dependabot[bot] avatar harrysolovay avatar joeyleadjig avatar joeyparis avatar rommyarb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

persistence-hooks's Issues

`setValue` does not update state unless a function is passed for the new state value

The state setter function only works if a function is passed for the new state value. e.g.

const [state, setState] = useStateAndSessionStorage("", "storage-key")

// Works, sets state to "Red"
setState(() => "Red")

// Does not work, state stays the same
setState("Red")

This is because we only reference the new value if the value is a function in the useStateAndPersistence method.

function useStateAndPersistence(createMethods, initial, key, options) {
   ...
   return [
    value,
    (updater, callback) => {
      const nextValue = typeof updater === 'function'
        ? updater(value)
        : value // This should be `updater` instead
      set(nextValue)
      setValue(nextValue)
      callback && callback()
    },
  ]
}

We may want to rename updater to something like getNextValue instead

[Feature Request] Allow cookie expiration to be adjusted after first render

Currently, useStateAndCookie won't update the expiration time if it is changed after the first render. This makes it difficult to have a flexible expiration time depending on a users choice (e.g. remind me tomorrow vs remind me next week). Technically we could use two separate instances of useStateAndCookie with the same key, but I don't know how I feel about two methods affecting the same cookie value.

My proposition would be to add a 3rd return argument in useStateAndPersistence called setOptions. Does this sound like a good approach and is it worth my time doing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.