Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions website/docs/write-code/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ In this example, the third parameter `persist` in the [storeValue()](/reference/

```jsx
export default {
fetch_name () {
storeValue('name', 'sam', true);
return appsmith.store.name;
},
update_name () {
storeValue('name', 'ben', true);
return appsmith.store.name;
},
// Pure getter: returns the name, or 'sam' if it's not set yet
fetch_name () {
return appsmith.store.name || 'sam';
},

// Setter: correctly forces the name to change to 'ben'
update_name () {
storeValue('name', 'ben', true);
return appsmith.store.name;
},
}
```
You can then refer to the stored computed value in widgets.
Expand Down