Help forum

Variable inside a component

  • Gerson CA

    1 year ago

    Hi I have this variable inside a component which is set with API data that I am sending via attributes. Then, on a list I am referencing the variable to display the data using the repeat option. This works fine in the component but on my main page I do not see the list data being rendered. Does it mean I have to move the variable up a level?
  • salma

    1 year ago

    There are a few ways to solve this. This page on contexts from the docs might help you decide which way to do it.

    You could choose to move the variable up a level. or send the data up with an event, or share it with a context.

    https://docs.nordcraft.com/contexts/overview
  • Gerson CA

    1 year ago

    Thanks for sharing but I’m still wondering if I were to share the data either via events or context, where would I set it in my main page? My list is inside my component so would I need to set another variable in the main page to display the data?
  • salma

    1 year ago

    It sounds like you want to define the variable on the main page and pass the variable data down into the component via an attribute
  • Gerson CA

    1 year ago

    Thanks this doc help I had to use the on attribute change event to update the data coming from the API
    👍1
  • salma

    1 year ago

    That’s great! The new docs are working!