question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use async as sync in hook!!

See original GitHub issue

Sorry 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:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

25reactions
felixfbeckercommented, Nov 3, 2016

your hook can return a promise

4reactions
exoscommented, Feb 20, 2018

Yes I fix it by the same way, but it’s an ISSUE.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found