appsmithorg / appsmithorg/appsmith-docs
[Docs]: Misleading logic in "Use Appsmith store" example (fetch_name)
- Dominant language
- MDX
- Stars
- 97
- Forks
- 280
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 8
Description
### Problem Statement
Hello,
I was reading the documentation on [Use Appsmith store](https://docs.appsmith.com/write-code/best-practices#use-appsmith-store) and I noticed that the code example provided does not represent a good practice, since a getter (fetch_name) is simultaneously acting as a setter.
The Issue: The function is intended to retrieve data, but it explicitly calls storeValue('name', 'sam', true). This means the function mutates the store every time it is called to read it.
### Current Example in Docs:
```js
export default {
fetch_name () {
storeValue('name', 'sam', true); // 👈🏼 This sets the value instead of just fetching it
return appsmith.store.name;
},
update_name () {
storeValue('name', 'ben', true);
return appsmith.store.name;
},
}
```
### Use Cases / User query reference
### Proposed Changes:
I suggest updating the example to clearly separate the concerns (Get vs. Set)
```js
export default {
// Pure getter
fetch_name () {
return appsmith.store.name;
},
// Setter
update_name () {
storeValue('name', 'ben', true);
return appsmith.store.name;
},
}
```
This change would make the distinction between reading from the store and writing to the store much clearer for new users.
BR
### Audio/Video Recording
_No response_
### Product Requirements Document
_No response_
### Other Relevant Links
_No response_
### Checklist
- [x] Reviewed existing documentation to ensure this request is not duplicated.
- [ ] Attached relevant media or supporting materials like links to the PRD, feature recordings, Slack or Discord links, and any other relevant resources.
Contributor guide
Assessment
This issue has not been assessed yet.