I've been scratching my head trying to figure out why this code isn't working as expected. I'm simply updating an object and expecting it to be refreshed in the DOM, but for some reason, that's not happening. The console log confirms that the object was updated, so why isn't it reflecting in my DOM?
import { render } from "solid-js/web";
import { createSignal, For } from "solid-js";
function ToDo() {
const getToDos = () => {
return [{
id: 1, name: 'one'
}, {
id: 2, name: 'two'
}]
}
const onTodoClick = (id: number) => {
const td = [...todos()];
const elem = td.find(t => t.id === id);
elem!.name = elem!.name + ' - Done';
console.log(td);
console.log(todos());
setTodos(() => td);
}
const [todos, setTodos] = createSignal(getToDos());
return (
<div>
<For each={todos()} >
{(todo) => <p onClick={() => onTodoClick(todo.id)}>{todo.name}</p>}
</For>
</div>
);
}
render(() => <ToDo />, document.getElementById("app")!);