Next.js Discord

Discord Forum

React prop handling

Answered
Spectacled Caiman posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Arinji
Yup, fetch api on the server so outside a useEffect
View full answer

14 Replies

What's removeTask
Spectacled Caiman
oh shit SORRY
Btw just to check, you are aware right you have opted out of nextjs and it's fetching behaviours right?
Spectacled Caiman
    function removeTask(id) {
        let tempTasks = tasks
        let removeIndex = tempTasks.map(item => item.id).indexOf(id)
        tempTasks = tempTasks.splice(removeIndex, 1)
        setTasks(tempTasks)
        console.log(tasks)
    }


Its really messy, im weak in js
@Spectacled Caiman what? can you explain
So basically nextjs caching is server side,doing an axiis fetch in a use effect is how you would fetch on the client side, just wanted to let you know.. it's fine if that's expected
Spectacled Caiman
oh... i just realized.. so should i use fetch api? like how its defined in the docs?
@Spectacled Caiman oh... i just realized.. so should i use fetch api? like how its defined in the docs?
Yup, fetch api on the server so outside a useEffect
Answer
Check out the docs since there is a lot of details there about fetching
Original message was deleted
Also
The reason it's not working is you aren't awaiting the handle deletion in the onclick
Spectacled Caiman
yes i got it working thank you so much!
@Spectacled Caiman please dont delete the original question, [mark the answer](https://nextjs-forum.com/post/1223641900712595556#message-1223641905259352086) instead. if Arinji's answer didn't help you fully, please also explicitly state so before deleting your question (it's alright, you won't be judged for saying an answer didn't help)