S
SolidJS•3y ago
nikiv.dev

Need help solve issue with createEffect, complex state

GitHub
GitHub - nikitavoloboev/kuskus: Fast todo app
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
11 Replies
nikiv.dev
nikiv.devOP•3y ago
GitHub
kuskus/All.tsx at main · nikitavoloboev/kuskus
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
nikiv.dev
nikiv.devOP•3y ago
I have a key event listener here that on return chooses if a todo should be edited or not
nikiv.dev
nikiv.devOP•3y ago
nikiv.dev
nikiv.devOP•3y ago
so from this go to this
nikiv.dev
nikiv.devOP•3y ago
nikiv.dev
nikiv.devOP•3y ago
the editable todo is this component
nikiv.dev
nikiv.devOP•3y ago
GitHub
kuskus/TodoEdit.tsx at main · nikitavoloboev/kuskus
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
nikiv.dev
nikiv.devOP•3y ago
GitHub
kuskus/TodoEdit.tsx at main · nikitavoloboev/kuskus
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
nikiv.dev
nikiv.devOP•3y ago
the issue I get is that this effect inside TodoEdit runs instantly its very confusing
nikiv.dev
nikiv.devOP•3y ago
if you wish to help please clone https://github.com/nikitavoloboev/kuskus
GitHub
GitHub - nikitavoloboev/kuskus: Fast todo app
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
nikiv.dev
nikiv.devOP•3y ago
then inside localhost press n key type a todo and press return it should create a new todo I am forced to enter return 2 times
createEffect(() => {
if (event()?.key === "Enter") {
untrack(() => {
if (focusedTodo() !== 0) {
untrack(() => {
if (editingTodo()) {
setEditingTodo(false)
} else {
setEditingTodo(true)
}
setTodoToEdit(focusedTodo())
})
}
})
}
})
createEffect(() => {
if (event()?.key === "Enter") {
untrack(() => {
if (focusedTodo() !== 0) {
untrack(() => {
if (editingTodo()) {
setEditingTodo(false)
} else {
setEditingTodo(true)
}
setTodoToEdit(focusedTodo())
})
}
})
}
})
ok this helped solve it 🎊

Did you find this page helpful?