Use async as sync in hook!!
See original GitHub issueSorry me for the bad title of this issue, but I can’t find a better one.
I want to check username is already taken or not before create a new user. So I write a method for my user model that do for me and call it in beforeCreate
hook.
The problem is findOne
method is async and new user added to database before I get the result of the username checker
method.
How can I wait for the result of checking username and after that save the user?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Top React Hooks — Sync and Async State
Hooks contains our logic code in our React app. We can create our own hooks and use hooks provided by other people. In...
Read more >How to use async functions in useEffect (with examples)
Using asynchronous functions in a useEffect hook is quite common, notably for data fetching. Let's see several ways of going about it!
Read more >How to use async function in useEffect?
Using async from within hooks is completely fine. Yes, it is true that using a hook may not always be the best choice...
Read more >Fetching Asynchronous Data with React Hooks
Probably the most common use-case for asynchronous code is to fetch a single resource when the component mounts. We need this all the...
Read more >How to use async function in React hooks useEffect ...
By default async functions are not supported by the useEffect hook of react, discover how to deal with that on React native and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
your hook can return a promise
Yes I fix it by the same way, but it’s an ISSUE.