Code Monkey home page Code Monkey logo

Comments (5)

valentyng avatar valentyng commented on May 23, 2024 1

It looks like the issue is here:

According to the documentation (https://reactjs.org/docs/react-component.html#setstate):

Think of setState() as a request rather than an immediate command to update the component.

liftedComponent.setState() doesn't update liftedComponent.state immediately.

So, every new renderCache is compared to the initial value, and if they are equal, the state isn't updated.

from focal.

valentyng avatar valentyng commented on May 23, 2024

A possible solution is moving structEq(liftedComponent.state.renderCache, renderCache) to shouldComponentUpdate (https://github.com/grammarly/focal/blob/master/src/react/react.ts#L116).

However, I'm not sure about the performance here.
@blacktaxi what do you think?

from focal.

blacktaxi avatar blacktaxi commented on May 23, 2024

That seems to be a good catch! Let me take some time to debug this. Not sure about moving structEq to shouldComponentUpdate, intuitively it indeed seems to ought to affect performance.

Another obvious solution could be to use the this.setState(prevState => ...) overload and perform the structEq call in the callback.

from focal.

oleksiilevzhynskyi avatar oleksiilevzhynskyi commented on May 23, 2024

@blacktaxi this.setState(prevState => prevState) triggers render. It looks like it doesn't make sense to use structEq here. Code - https://codesandbox.io/s/0ol9q3q38w

from focal.

blacktaxi avatar blacktaxi commented on May 23, 2024

Added a repro and tracking this in #27 now

from focal.

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.