PricingBlog

Set variable in child from context

  • stockton_f-1270386352097329212

    Stockton

    1 year ago

    On my parent page I have an API call that is being passed down in context via a formula.

    In the child page, I want to set the data from the formula in a variable.

    If I set the variable's initial state to the context, I think there's a timing issue.

    When the variable checks the initial state, the context is empty. Then the context gets it's data but doesn't update the variable.
  • andreasmoller-1270386851705782395

    Andreas Møller

    1 year ago

    We dont currently have a mechanism for triggering events when context changes like we do with attributes
  • The only trick I can think of is having the parent component pass the context bar as a variable
  • stockton_f-1270387310743126109

    Stockton

    1 year ago

    What's the context bar?
  • andreasmoller-1270387471523385385

    Andreas Møller

    1 year ago

    Fat fingers on an iPhone keyboard
  • Context var
  • Sorry pass the context bar as an attribute it should say 🙂
  • stockton_f-1270387948478529546

    Stockton

    1 year ago

    lol thanks

    Is that literally just context or ctx
  • lucasg-1270388828263419975

    Lucas G

    1 year ago

    Pass the context data into the attribute of the child component I think is what he's saying
  • stockton_f-1270389008546926683

    Stockton

    1 year ago

    Right, I was thinking there's a special context variable or something...
  • lucasg-1270389417478979594

    Lucas G

    1 year ago

    Hmm I need to double check a setup I did then
  • Because I'm pretty sure I did what you are describing here
  • A variable's initial state being set from a context
  • But I thought it worked 🤔
  • lucasg-1270390533658775696

    Lucas G

    1 year ago

    Ah nvm I think what I did was leave the variable empty then onLoad, a 100ms delay then set the variable with the context data
  • Which was enough for the API data to be available
  • lucasg-1270390912580587612

    Lucas G

    1 year ago

    Though the attribute approach might be better in case the API call takes a long time
  • stockton_f-1270394929436426282

    Stockton

    1 year ago

    Alright, back to the ole' attribute method lol
  • Thanks guys 🙂