SolidJSS
SolidJSโ€ข2y agoโ€ข
8 replies
Ditto

How can I synchronize two stores without running into an infinite loop?

The following code triggers an infinite loop:

const [store1, setStore1] = createStore({a: 1, b: 2});
const [store2, setStore2] = createStore();

createEffect(() => {
  setStore1(store2);
});

createEffect(() => {
  setStore2(store1);
});


How can I update one when the other changes and avoid this?
Was this page helpful?