score:1

Accepted answer

i can't comment because i've only just made an account

that being said i can update this answer if you can provide a bit more information :)

where are you checking for the result of the new chore being set? i can see in the code you posted that there's the new chore index being logged in the updatechore function but not the newchore itself. have you tried logging in another useeffect? like...

useeffect(() => {
  console.log(newchore);
}, [newchore]);

* update

seeing as you're only using newchore inside the popup, you could try moving the usestate call for newchore inside of the popup body then passing it to the updatechore function like this

const [showpopup, hidepopup] = usepopup('popup', ({ message, handleclose }) => {
  const [newchore, setnewchore] = usestate("");

  useeffect(() => {
      console.log(newchore);
  }, [newchore]);

  return (
    <div classname="modal">
        <div classname="modalinner">
            <button 
                classname="modalclose"
                onclick={handleclose}>
                x
            </button>

            <div classname="modalinner2">
                <p classname="modalheading">previous chore(s)</p>
                <p classname="modalchore">{message}</p>

                <p classname="modalheading">new chore {newchoreindex}</p>
                <input
                    classname="newchoreinput"
                    placeholder="new chore"
                    onchange={(e) => {setnewchore(e.target.value)}}
                />

                <button 
                    classname="modalsubmit"
                    onclick={() => {
                        updatechore(newchore)
                        hidepopup()
                    }}>
                    update chore
                </button>
            </div>
        </div>
    </div>
  )
});

this will stop the useeffect on setchore working outside of the popup though as it's not in scope, so you'll probably have to move that into the popup as well to see if it's updating on change.


Related Query

More Query from same tag