undux icon indicating copy to clipboard operation
undux copied to clipboard

exhaustive-deps issue

Open kaatt opened this issue 4 years ago • 0 comments

My code:

const App = () => {
  useSelectedObj({ a: 1 })
  return <>...</>
}

export function useSelectedObject(obj) {
  const store = Store.useStore()
  useEffect(() => {
    store.set('obj')([obj])
    return () => store.set('obj')(null)
  }, [obj]) // eslint error here
}

The eslint error I get:

React Hook useEffect has a missing dependency: 'store'. Either include it or remove the dependency array                                                              react-hooks/exhaustive-deps

Including store in the dependency array makes it go into an infinite loop. What am I doing wrong here and what should I do instead? Should I silence the eslint error?

Didn't find anything in the documentation or existing issues regarding this.

kaatt avatar Feb 25 '20 11:02 kaatt