fingerprintjs/fingerprintjs-pro-react

Updating state in `useVisitorData` might cause a warning in React < 18

molefrog opened this issue · 1 comments

Hi! Prior to React 18 there was a warning that the library would show if you tried to set state in already unmounted component. Luckily, in the newest version they made this less strict so that application developers don't have to guard state updates with any additional checks.

There are three places where we update the state in an asynchronous function inside the useVisitor hook. Even though it's not the case anymore, since this is a library, there could be clients who still use React 17 or earlier, it would be nice if we could prevent any warnings from happening.

The fix can be really straight forward like:

const isComponentUnmounted = useRef<boolean>(false)

useEffect(() => {
  return () => isComponentUnmounted.current = true
}, [])

// inside an async func
if(isComponentUnmounted.current) return
setState(...)

Thanks for reporting Alexey, sorry we couldn't prioritize addressing this at the time. As it's only a warning affecting React 17 and the React SDK now officially supports only React 18 or higher, I am going to close this.

@ilfa let me know if you prefer a different course of action, we can always reopen it.