GithubHelp home page GithubHelp logo

Comments (8)

valotas avatar valotas commented on May 27, 2024

from preact-context.

bradlc avatar bradlc commented on May 27, 2024

Hey George,

Sounds good, thanks! 😎

Had a quick look, and if I change the Consumer component's shouldComponentUpdate method to just return true; it works as expected. So maybe it's an issue with the condition here?:

return (
this.state.value !== nextState.value ||
getRenderer(this.props) !== getRenderer(nextProps)
);

from preact-context.

bradlc avatar bradlc commented on May 27, 2024

Actually, although changing it to return true; fixes the test case above, it doesn’t fix the original issue that I’m having on a project (again, it works fine with React.createContext). I will create another reduced test case for that if I can.

Edit: the issue on my project was actually caused by this preact bug, so you can disregard this comment

from preact-context.

valotas avatar valotas commented on May 27, 2024

@bradlc the problem is that preact mutates the state instance on each update hence the this.state.value !== nextState.value check is always true. You have to make sure that you pass a new instance of the value to the Context.Provider (ex: <Context.Provider value={{ ...this.state }}>, see your updated example).

from preact-context.

valotas avatar valotas commented on May 27, 2024

I'll try to catch up with some of the preact maintainers in order to provide a proper solution for that as it looks like it will be a problem that many preact users might have.

from preact-context.

marvinhagemeister avatar marvinhagemeister commented on May 27, 2024

This issue is caused by using an older release of preact. With the most recent version 8.3.1 I can't reproduce the issue anymore and the example works exactly the same as for react.

from preact-context.

bradlc avatar bradlc commented on May 27, 2024

You’re right, updating the CodeSandbox to 8.3.1 fixes the issue. Thanks!

from preact-context.

valotas avatar valotas commented on May 27, 2024

thanks a lot for the clarification @marvinhagemeister !

from preact-context.

Related Issues (17)

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.