Ditto
Ditto
SSolidJS
Created by Ditto on 4/22/2024 in #support
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);
});
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?
9 replies
SSolidJS
Created by Ditto on 4/22/2024 in #support
What is the most idiomatic way of disabling an effect after a condition is met?
Is it possible to disable an effect after some condition is met or should I just use an early return?
const [value, setValue] = useSignal<number | undefined>();

createEffect(() => {
if (value() !== undefined) {
// do something with value() then disable this effect
}
})
const [value, setValue] = useSignal<number | undefined>();

createEffect(() => {
if (value() !== undefined) {
// do something with value() then disable this effect
}
})
6 replies