Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with @typescript-eslint/no-unnecessary-condition #111

Open
crisfcodes opened this issue Jun 19, 2021 · 0 comments
Open

Problem with @typescript-eslint/no-unnecessary-condition #111

crisfcodes opened this issue Jun 19, 2021 · 0 comments

Comments

@crisfcodes
Copy link

I'm using this code to validate if some hook is used inside an specific context but I obtain the following error: ESLint: Unnecessary conditional, value is always falsy.(@typescript-eslint/no-unnecessary-condition), what is the correct way to handle this, disabling the rule or is there another way?

import React from 'react'

import {AppStateContext} from '../components/containers'

export function useAppState() {
  const context = React.useContext(AppStateContext)

  if (!context) { // error comes from here
    throw new Error('useAppState must be used within the AppStateProvider')
  }

  return context
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant