Cold
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Once all notifications have had their relevant props applied, for some reason,
setNotifications
then works.63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
So, to summarize, I have created a separate
localNotifications
state that is not shared between components. This acts as an intermediary store, so that the data can be processed properly, setting shouldNotify
accordingly63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Here is what I did:
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
I have managed to fix this!
But I am absolutely not happy with the solution.
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
My understanding of passing a variable into the array for useEffect is that this watches for changes to the value, running the method passed if it changes
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Now, my first thought was that maybe the same thing was happening, where
notifications
does not get updated. But if this were the case, then the Watcher
component would not have been able to detect the change!63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
watcher.tsx
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
New code in
_app.tsx
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
What the hell is going on!?!?!?!
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
@Bao @ bhuynh.dev @FinalDev Hi all, I have completely refactored my code.
Instead of the previous solution, I have moved the SSE functionality back into
_app.tsx
, with a separate Watcher
component that watches for changes to the notifications
store, pushing any notifications marked with shouldNotify
.
Now interestingly, this works to an extent. My notifications get pushed successfully, and what should happen, is on the next pass, all existing notifications should have the shouldNotify
prop marked as false
.
But this interestingly doesn't happen. Instead, if I run a console.log
for notifications
in _app.tsx
, this always returns undefined!!!
What's stranger is that if I, say for example, make a change to my code and save it whilst running in dev mode, the notifications
state updates correctly with console.log
outputting the correct data!63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Are you saying, set it to [] and then set it to [...data]?
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Not quite sure what you mean by this?
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Nope, didn't fix it
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Just out of curiosity I am going to try moving the functionality to my NavBar component...
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Wait a minute.. could it be something to do with SseHandler not returning anything to render?
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
As I have also tested this with
useUser
and useWarningStore
63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
Yes, specifically in
SseHandler
it seems any state changes are completely disregarded63 replies
RReactiflux
•Created by Cold on 12/22/2024 in #react-forum
State not getting updated
SseHandler
must be a child of the provider for it to use the hook63 replies