I am unable to see what's wrong with this code, where I'm simply trying to update the object and get it refreshed in DOM, which doesn't happen. The console log does say that the object was updated, but why is this isn't updating 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")!);