4 ms·
I read over the React integration here, and it seems like an unsafe approach to React 18+ by monkey-patching React internals state transitions, as well as mutat
by jitl 4y ago
I read over the React integration here, and it seems like an unsafe approach to React 18+ by monkey-patching React internals state transitions, as well as mutating refs during rendering which can break during concurrent updates.
Some abuse of the internals may be "safe" because React Devtools relies on this stuff, but I would be very nervous betting production correctness on this strategy long-term. Maybe it's worth it? Really hard call.
Here's the details: https://github.com/preactjs/signals/blob/main/packages/react/src/index.ts https://github.com/preactjs/signals/blob/main/packages/react...
- zerovox 4y agoI had a similar response when reading "React adapter allows you to access signals directly inside your components and will automatically subscribe to them." I don't believe this is worth it. The implementation is fairly dangerous and fragile as you point out, all in order to simplify something fairly clean/reacty such as `const value = useSignalValue(signal)` into `signal.value`.
- iainmerrick 4y agoThe difference (as I understand it) is that you don’t need to list your dependencies as you would with a hook, and you can call it anywhere. I find this approach conceptually simpler than hooks.
- capableweb 4y agoInvisible dependencies and avoid referential transparency sounds more complex to me than the opposite (upfront dependencies and referential transparency), not simpler.
- jitl 4y agoSure, but you could at least wrap the whole component in observer(MyComponent) like Mobx and avoid all this skullduggery with the internals.
- AgentME 4y agoYeah, it seems like a lot of effort to do things in a fragile way when regular hooks are capable of getting similar results in a standard way.