S
SolidJS8mo ago
Osman

createStore not reactive

I have the following code:
function handleInput(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element}) {
const input = event.currentTarget.id;

setQuestions(questionID, 'answer', input)
console.log(questions[questionID].answer);
}

createEffect(() => {
console.log(questions[questionID].answer);

})

function isChecked(answerOption: string, answer: string) {
console.log(questions[questionID].answer);

return answer[0] === answerOption
}
function handleInput(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element}) {
const input = event.currentTarget.id;

setQuestions(questionID, 'answer', input)
console.log(questions[questionID].answer);
}

createEffect(() => {
console.log(questions[questionID].answer);

})

function isChecked(answerOption: string, answer: string) {
console.log(questions[questionID].answer);

return answer[0] === answerOption
}
When updating the questions[questionID].answer in handleInput, it does not trigger the createEffect nor the isChecked function. isChecked is used as a flag function for a classList attribute
2 Replies
lobster theremin
Can you provide a reproduction in the Solid playground?
Osman
Osman8mo ago
I figured it out. I had an array of objects, which was being shallow copied into the context. Had to do deep copying to make the reactivity work