react-mentions
react-mentions copied to clipboard
Async fetch not working with Apollo Graphql
Steps to reproduce:
const fetchUsers = (query, callback) => {
if (!query) return
getAutocompleteUsers({
variables: {
username: query,
},
}).then((usersResult) => {
callback(usersResult?.data?.getAutocompleteUsers)
})
}
- Use apollo to fetch a new list of users as shown above to fetch a list of users
- Get the list of users and then input as argument to callback function
Expected behaviour:
The autocomplete should update according to the fetched results of getAutocompleteUsers
Observed behaviour: No list is displayed when the trigger '@' is typed in, I suspect due to async issues.
Workaround: I have to fetch a static list of users which is not scalable
Hello @andywong418, I cannot reproduce your bug. https://codesandbox.io/s/react-mentions-541-j2bym. Can you provide a reproducible example ?
An error occurs when there's a slight time delay https://codesandbox.io/s/react-mentions-541-forked-mj9in (decreasing timeout to 1000 kinda works again) @ThibautMarechal