Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NgaMoon
Frequent Visitor

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 2
dm-p
Super User
Super User

Hi @NgaMoon,

 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




NgaMoon
Frequent Visitor

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 ?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.