sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

new react and socket ish related issue #122

Closed jadenRuplal closed 2 years ago

jadenRuplal commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

mern

What's the problem you're trying to solve?

data loss at some point

Post any code you think might be relevant (one fenced block per file)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

no errors

What is your best guess as to the source of the problem?

use effect pulls original state data

What things have you already tried to solve the problem?

so many things I can't count with ta's for hours and after that 3 more hours with no prevail

Paste a link to your repository here https://github.com/jadenRuplal/project-4-carbid-api https://github.com/jadenRuplal/project-4-carbid-client

jadenRuplal commented 2 years ago

If someone can hop in a breakout room to see this that would be great its hard to go over on text

jadenRuplal commented 2 years ago

socket.on('recieve_message', (data) => { console.log('line 80 all comments', allComments) setAllComments((prevAllComments) => { console.log('inside set function', prevAllComments) return [...prevAllComments, data] }) })

Previous to this code block it was just setAllComents. With the addition of an arrow function, the function no longer grabs the original use state but grabs the updated state and appends the data to the array of comments.