Skip to content

Commit f066845

Browse files
committed
fix: corrected misleading storeValue logic in best practices
1 parent 8826eec commit f066845

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

website/docs/write-code/best-practices.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ In this example, the third parameter `persist` in the [storeValue()](/reference/
4545

4646
```jsx
4747
export default {
48-
fetch_name () {
49-
storeValue('name', 'sam', true);
50-
return appsmith.store.name;
51-
},
52-
update_name () {
53-
storeValue('name', 'ben', true);
54-
return appsmith.store.name;
55-
},
48+
// Pure getter: returns the name, or 'sam' if it's not set yet
49+
fetch_name () {
50+
return appsmith.store.name || 'sam';
51+
},
52+
53+
// Setter: correctly forces the name to change to 'ben'
54+
update_name () {
55+
storeValue('name', 'ben', true);
56+
return appsmith.store.name;
57+
},
5658
}
5759
```
5860
You can then refer to the stored computed value in widgets.

0 commit comments

Comments
 (0)