Skip to content

Commit

Permalink
docs: Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
finom committed May 30, 2023
1 parent 0b2c6b4 commit e26dac2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,21 @@ export const { loadUsers, createUser } = users;
export default users;
```
> Tip: Use `use` hook provided by React to call your async methods.
```tsx
import { use } from 'react';
import users, { loadUsers } from './store/users';

const MyComponent = () => {
const users = use(loadUsers());

return (
<div>{users.map(/* ... */)}</div>
);
}
```
Then you can import the sub-store and the methods to your component.
```ts
Expand Down Expand Up @@ -390,7 +405,6 @@ const settings = new Settings();
export default settings;
```
----------
We import methods and sub-stores separately but you still can access methods of `users` instance. In other words you still have 2 ways to call the method from your components.
Expand Down Expand Up @@ -668,6 +682,8 @@ Your file structure is going to look like that:
/protected.ts
```



### Conclusion

1. Using patterns above we restrict the code and provide only one way to import the store by component modules: `import publicData, { method1, method2 } from './store/foo/bar/baz` where default export is used for "data" and named export is used for actions. It doesn't make sense to provide full store access to other modules that aren't related to the store.
Expand Down

0 comments on commit e26dac2

Please sign in to comment.