Skip to content

Commit bde0b83

Browse files
committed
ref: #187 update 09 - 11 update readme async await
1 parent c4fdd2c commit bde0b83

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

hooks/11_TableAxios/Readme.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ export const getMembersCollection = (): Promise<MemberEntity[]> => {
6767
+ }));
6868
```
6969

70+
- Adding async await calling member api
71+
72+
To make the async await work, we should install
73+
- `npm install -D @babel/plugin-transform-runtime`
74+
- `npm install -P @babel/runtime`
75+
76+
and add to the .babelrc
77+
78+
_.babelrc_
79+
```bash
80+
"plugins": ["@babel/plugin-transform-runtime"]
81+
```
82+
83+
_./src/components/memberTable.tsx_
84+
```diff
85+
- const loadMemberCollection = () => {
86+
- getMembersCollection().then(memberCollection =>
87+
- setMemberCollection(memberCollection)
88+
- );
89+
90+
+ const loadMemberCollection = async () => {
91+
+ const memberCollection = await getMembersCollection();
92+
+ setMemberCollection(memberCollection);
93+
```
94+
7095
- Aaaand... we don't need to add any update on the rest of the application, why?
7196
The function is providing the same contract, it returns a promise<MemberEntity[]>,
7297
let's give a try:

0 commit comments

Comments
 (0)