eslint-plugin-ts-react-hooks

1.0.4 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.41latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.41
1.0.30
1.0.25
1.0.10
1.0.00
0.1.11
0.1.00
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i eslint-plugin-ts-react-hooks

Weekly Downloads

7

Version

1.0.4

License

MIT

Unpacked Size

68.6 kB

Total Files

5

Last publish

Collaborators

  • anjianshi