Giter VIP home page Giter VIP logo

Comments (3)

drcmda avatar drcmda commented on May 5, 2024

It’s using reference equality for change detection. Setting the same object won’t cause rerendering, similar to how Redux reduces state.

from zustand.

dy avatar dy commented on May 5, 2024

The problem persists is even if passing clone of the object

// global-ish history tracker
export const [ useHistory ] = create(set => {
  let history = createBrowserHistory()

  const unlisten = history.listen((location, action) => {
    set({...history})
  })

  let delegation = delegate('a', 'click', e => {
    e.preventDefault()
    history.push(e.delegateTarget.getAttribute('href'))
  });
  return {...history}
})

from zustand.

JeremyRH avatar JeremyRH commented on May 5, 2024

It isn't updating because all the enumerable properties on history are the same. The check to update state is a "shallow equal" check. It will first check if the value is equal and if not, check all enumerable properties for equality. Even though you created a new history object, the enumerable properties were the same so it did not set the state.

It looks like you are trying to call set when the history event is dispatched. You should create your own state with { location } and set the location value in the listener. If you need access to the history object outside of the store, create it outside of the store in a module and import it whenever you need it.

from zustand.

Related Issues (20)

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.