1.0.4 • Published 8 months ago

eslint-plugin-ts-react-hooks v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

eslint-plugin-ts-react-hooks

Use TypeScript to enhance react-hooks/exhaustive-deps rule's functional. Auto ignore stable items from custom hook.

Usage

In ESLint config:

module.exports = [require('eslint-plugin-ts-react-hooks').configs.recommended]

Example

import React, { useCallback, useState, useReducer, useRef } from 'react

function useCustomHook() {
  const [state3, setState3] = useState(3)
  return { state3, setState3 }
}

function MyComponent({ value }: { value: number }) {
  const [state, setState] = useState(1)
  const [state2, dispatch] = useReducer((state: number, action: number) => state + action, 2)
  const ref = useRef<number|null>(null)

  const { state3, setState3 } = useCustomHook()

  const callback = useCallback(() => {
    console.log('call')
  }, [])

  useEffect(() => {
    console.log(value)
    if (typeof ref.current === 'number') {
      setState(ref.current)
      dispatch(ref.current)
      setState3(ref.current)
      callback()
    }
  }, [value])      // only 'value' need put in dependencies

  return <div>content</div>
}
1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago