alexamy
alexamy
SSolidJS
Created by alexamy on 7/3/2024 in #support
Granular update of store array doesn't trigger effects depending on the whole array
I am really puzzled with proper setup for store array management. I am creating the array in the store:
const [store, setStore] = createStore({
points: [
{ x: 50, y: 50 },
{ x: 100, y: 100 },
],
});
const [store, setStore] = createStore({
points: [
{ x: 50, y: 50 },
{ x: 100, y: 100 },
],
});
And updating elements in it (important: I can not update the whole array):
function updatePoint(i: number) {
setStore("points", i, () => ({
x: Math.random() * 200 + 20,
y: Math.random() * 200 + 20,
}));
}
function updatePoint(i: number) {
setStore("points", i, () => ({
x: Math.random() * 200 + 20,
y: Math.random() * 200 + 20,
}));
}
But neither of these effects are triggered:
createEffect(() => {
console.log('array of points', store.points);
});

createEffect(() => {
console.log('individual points', store.points[0], store.points[1]);
});
createEffect(() => {
console.log('array of points', store.points);
});

createEffect(() => {
console.log('individual points', store.points[0], store.points[1]);
});
Why these effects are not triggered and how to fix it? Demo: https://stackblitz.com/edit/solidjs-store-array-1?file=src%2FApp.tsx UPD: funny that individual points effect is working in SolidJS playround: https://playground.solidjs.com/anonymous/6e486319-8488-4651-82d2-15a7602e7afa
26 replies
SSolidJS
Created by alexamy on 2/21/2024 in #support
React is not defined when using custom server directory for Vite
Hi! If I use custom directory on the same level as src for dev mode in Vite & Solid setup, I get React is not defined error. Steps to reproduce: 1. Create new Solid project with npm create vite@latest 2. Move index.html, index.tsx to separate dev directory 2a. Change import in index.tsx to point to file from src directory 2b. Add dev directory to tsconfig.json include. 3. Run vite dev mode: vite serve dev Expected: Web page is loaded and working correctly. Actual: React is not defined in solid-js_web. Example repo: https://github.com/alexamy/solid-custom-serve-directory
2 replies