Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Stores settings and values

Hello,

I create a custom visuals using react in code. How can I stores Visuals setting and my React value state when I change page reports or refresh (F5) my page without saving report. I have 2 options: persistProperties or Local Storage API. Which option is more suitable for my situation? Hope I have suggestions

2 Replies

  • dm-p's avatar
    dm-p
    Super User

    Hi Anonymous,

     

    If you want to store via the visual properties, you will need to create a text/string-valued property that can store your object as a string representation (e.g., through JSON.stringify) and save it via persistProperties. You can omit the property from being displayed when you build the properties pane for your visual, and it will still work; it just has to be valid for your visual capabilities. I have a feature flag for debugging purposes which will render it when I want to inspect it this way, but that's up to you as to whether you want to do something similar.

     

    When it comes to retrieval, you will need to deserialize this to a valid object (e.g., through JSON.parse) when the visual is re-initialized.

     

    I believe that you can use local storage also, but it's not something I have experience with to advise further. Anecdotally, the folks I know who use it get on OK with it.

     

    Regards,


    Daniel

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello dm-p ,
      I try to use persistProperties in my code to store the visual properties and React.useState value, but I don't know how to use it. I don't have any example for my code. Can you share me some infor how to use this persistProperties ?