Pricing Blog

localstoage vs variable

  • enginhear-1427358248692088993

    enginhear

    21 hours ago

    Hello,

    I have a repeated element based on a localstorage. It works perfectly: when the localstorage is updated with a new element, it updates on the page without refresh.
    But if I change the value of one of its setting it seems less responsive and I have to refresh the page to see it, even if it updated instantly in the localstorage.
    To check, I changed the repeat element to be base on a variable and the problem is resolved. I find this behavior surprising because updating the localstorage works in one case but not the other.

    To make things clearer here is a picture to illustrate. the localstorage contains "image_url" and "favorite". if the user generates a new image, the localstorage is updated and the new image is shown on the page. But if I click on the icon to change "favorite", it is updated in the localstorage but not on the page (or if I click one time the view changes, but if I click again it does not).

    So I am wondering: is there a difference between updating the localstorage and a variable? Is this a normal behavior?
    1427358248956334273-Capture_decran_2025-10-13_a_20.11.42.png
  • lucasg-1427362083506356285

    Lucas G

    21 hours ago

    Nordcraft doesn't subscribe to changes on localStorage. If you're seeing it update without a refresh then it's because the variable you're using to repeat over was itself updated as well.

    Any time you want to store data in local, you'll have to 'manually' push and pull from it. That's standard behaviour
  • lucasg-1427362730352054363

    Lucas G

    21 hours ago

    Maybe worth clarifying that you don't need to refresh a page to pull data from localStorage, you can do so at any time
  • lucasg-1427363587646816428

    Lucas G

    21 hours ago

    Local storage can be used for things like local settings that don't change often (and don't break the app when they are cleared) but I'd say you're better off using variables or other Nordcraft features for something like UI state and similar as they're much easier to work with
  • lucasg-1427364497408135190

    Lucas G

    21 hours ago

    To directly answer your question, yes, Nordcraft variables are different from localStorage. Variables and similar live in Nordcraft's state (window, etc) while local storage is a separate thing in the browser
  • enginhear-1427373996076306462

    enginhear

    20 hours ago

    Thank you for your response, that's what I thought. I will now use variable for this task!