Skip to content

Commit

Permalink
Update recommend-practices.md
Browse files Browse the repository at this point in the history
  • Loading branch information
e7h4n authored Dec 9, 2024
1 parent 083497c commit e05ad32
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/recommend-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

## Naming

Add a suffix `Atom` to `Value` & `Computed`, and use `Effect` for `Effect`. Since we often need to get values from Atoms in many scenarios, adding the suffix after Atom can avoid naming conflicts.
Add the suffix `Atom` to `Value` and `Computed` and use `Effect` for `Effect`. Since we often need to get values from Atoms in many scenarios, adding the suffix after Atom can avoid naming conflicts.

```typescript
const countAtom = $value(0);
const doubleAtom = $computed((get) => get(countAtom) * 2);
const updateCountEffect = $effect((get, set, val) => {
set(countAtom, val);
});
// ...
const count = get(countAtom) // will not conflict with normal value
// in react component
const updateCount = useSet(updateCountEffect) // Effect suffix is useful for this

return <button onClick={() => updateCount(10)}>update</button>
```

## Do not use `store` directly
Expand Down

0 comments on commit e05ad32

Please sign in to comment.