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.

This should be error right?


    if (thing) {
        return;
    }

    const [state, setState] = useState(null);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Geliocommented, Feb 6, 2019

Right, that is correct 👍 Thanks for pointing it out! This is a very interesting case that I did not think of beforehand.

I will try to cover this case in the nearest future

2reactions
Geliocommented, Mar 9, 2019

Good news 😄 I just published tslint-react-hooks@2.0.0-alpha.1 that reports violations for hooks used after early returns.

You can install it with:

npm install tslint-react-hooks@2.0.0-alpha.1 --save-dev

I am looking for your opinions 😄 Let me know if it works fine for you after installing the latest alpha.

If everything is good, I will release 2.0.0 to the public

Read more comments on GitHub >

github_iconTop Results From Across the Web

Return Early Pattern - Medium
R eturn early is the way of writing functions or methods so that the expected positive result is returned at the end of...
Read more >
Are Early Returns Any Good? - Better Programming
The idea behind returning early is that you write functions that return the expected positive result at the end of the function.
Read more >
The early return pattern in JavaScript - Go Make Things
With the early return pattern, you check for the opposite of the thing you want, and return early to end the function when...
Read more >
Should I return from a function early or use an if statement?
Early return if there is some obvious dead end condition to check for right away that would make running the rest of the...
Read more >
Return early - DEV Community ‍ ‍
An early return, or “return early” is an approach to keep readability in functions and methods. It is always considered a wise choice...
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