realar-project / realar

5 kB Advanced state manager for React

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No reading zone in logic factories and constructors

betula opened this issue · comments

class CounterLogic {
  @prop value = 0;
  inc = () => (this.value += 1);

  constructor() {
    console.log(this.value);
  }
}

let n = 0;

const Counter = observe(() => {
  const { inc } = useLocal(CounterLogic);

  console.log("Render", n++);

  return <button onClick={inc}>+</button>;
});

export const App = () => <Counter />;

Edit on CodeSandbox

The component was subscribed to value and reacted the first time on It change, but not used inside.