Pls help with fetch
#2994
-
Beta Was this translation helpful? Give feedback.
Answered by
kubk
Jun 19, 2021
Replies: 1 comment 1 reply
-
You are losing <Button onClick={userStore.getUsers}/> This won't work because of the JS nature. There are few ways to fix it:
<Button onClick={() => userStore.getUsers()}/>
<Button onClick={userStore.getUsers}/>
...
class UserStore {
...
getUsers = () => {
...
}
}
<Button onClick={userStore.getUsers}/>
...
class UserStore {
...
constructor() {
makeAutoObservable(this, {}, { autoBind: true })
}
getUsers() {
...
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
iChenLei
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are losing
this
in your example. It looks like you are callinggetUsers
like this:This won't work because of the JS nature. There are few ways to fix it:
this
: