PricingBlog

How to update a value in Context?

  • jak_io-1234539091677413457

    jak

    1 year ago

    I've added approx 30 views to the video 'How to use Context in toddle' 🤣 but still can't update the value... consuming the value is fine. I tried to cover my set up as quickly as possible, sorrys its 4mins.
    https://jam.dev/c/3f337f22-feb3-4883-84a0-7c8c0d3031da

    The loom video from Max has been useful, but unfortunately doesnt cover updating context
    https://discord.com/channels/972416966683926538/1022093334354853928/1232222401807257600
  • andreasmoller-1234545253231493252

    Andreas Møller

    1 year ago

    We appreciate the boost!
    Context values are formulas, so when ever the value producer by the formula changes, so does the context value
  • jacobkofoed-1234604377872924693

    Jacob Kofoed

    1 year ago

    Hi @jak I think everything you are doing is correct, but there are some caveats when working with context that are important for your example:

    When editing a component in the toddle-editor, you are editing it as a stand-alone and as if it was the root of the app. So it is impossible to actually have a real context provider when previewing a consumer component. Instead, subscribed contexts are faking themselves by feeding their initial values, usually based on the test-values. Calling workflows etc. will not update the values of the provider. This is likely a temporary limitation as we figure out a strong solution to previewing context in the editor, but there are some ugly edge-cases we must handle.

    You can create a page/component with the provider and the consumer (as a child) to test with a real context provider. In your example, if you add a page with your provider context and the consumer usecontext as a child, I suspect it actually works both in the editor and in production!

    Context is still a v1 feature, and we are still monitoring feedback (including yours 🙌 ) so we can make improvements.

    Let me know if you still have any issues, perhaps I can set up a demo-project to showcase some basic context usage.
  • jak_io-1234894489735401573

    jak

    1 year ago

    Thanks for the detailed explanation @Jacob Kofoed .. much appreciated. I haven't yet managed to get this to work, but I will persist. Today, I decided to focus on getting other fundamentals working in Toddle instead
    💪1