ThirtyTech / yasml

Yet another react state management library. Easy to work with and feels like regular hooks.
https://yasml.vercel.app
MIT License
0 stars 0 forks source link

Codegen traps values when using function in useSelector #2

Open jsheely opened 3 months ago

jsheely commented 3 months ago

I noticed that when I toggled on and off the codeGeneratorYasmlPlugin that the example


export function CounterSetter() {
  const { increment } = useGlobalState();
  const state = useGlobalState((state) => ({
    test: state.counter * 2,
    rawr: "goes the lion",
  }));
  return <button onClick={() => increment()}>Increment {state.test}</button>;
} 

The value in test could get trapped and never update on click.

jsheely commented 3 months ago

I believe I knew this before. The issue I had tested is that increment is the only variable being used so with codegen that gets put automatically into the useGlobalState hook which causes counter to get trapped and never used.

I think this is the desired behavior even if it is not obvious.