#Need help solve issue with createEffect, complex state

18 messages · Page 1 of 1 (latest)

livid ruin
#

I have a key event listener here

#

that on return chooses if a todo should be edited or not

#

so from this go to this

#

the editable todo is this component

#

the issue I get is that this effect inside TodoEdit runs instantly

#

its very confusing

#

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

livid ruin
#
  createEffect(() => {
    if (event()?.key === "Enter") {
      untrack(() => {
        if (focusedTodo() !== 0) {
          untrack(() => {
            if (editingTodo()) {
              setEditingTodo(false)
            } else {
              setEditingTodo(true)
            }
            setTodoToEdit(focusedTodo())
          })
        }
      })
    }
  })