avkonst / hookstate

The simple but very powerful and incredibly fast state management for React that is based on hooks
https://hookstate.js.org
MIT License
1.65k stars 107 forks source link

`interceptReactHooks` fails to override already imported `useEffect` when running in module environment #412

Open HexaField opened 16 hours ago

HexaField commented 16 hours ago
import { useEffect } from 'react'
import { hookstate } from '@hookstate/core'

console.log(useEffect) // this will be the old useEffect implementation

Switching over from mocha to vitest and CJS to ESM caused my tests to fail, but if I swap the order of the above imports, the tests pass fine. Generally it is a bad idea to override other dependencies, and in the case of ESM environments, it seems like the imports are reconciled different and can more easily fail.

avkonst commented 13 hours ago

yes, it is... but there was no other way to deliver ergonomics with the rigid API of react... I think you can useHookstateEffect instead and it should not be dependent on the order of imports