The list is not updated when adding a new item via useState()

Hey, everybody

A problem (misunderstanding) has arisen with the useState hook.
I have two custom hooks:

1) useLocalStorage.ts

Used to interact with localstorage.

2) usePlaylist.ts

Used to add/remove playlists, as well as get the full p…


This content originally appeared on DEV Community and was authored by Никита Бобченок

Hey, everybody

A problem (misunderstanding) has arisen with the useState hook.
I have two custom hooks:

1) useLocalStorage.ts

Image description
Used to interact with localstorage.

2) usePlaylist.ts

Image description
Used to add/remove playlists, as well as get the full playlist

I have a react component with which I add a new playlist using the usePlaylist hook

Image description

And then I have a react component that displays a list of playlists:

Image description

BUT AFTER ADDING A NEW PLAYLIST, THEIR LIST IS NOT UPDATED(only when the page is refreshed)

I have tried a lot of things, but maybe I missed something or misunderstood something, help please.


This content originally appeared on DEV Community and was authored by Никита Бобченок


Print Share Comment Cite Upload Translate Updates
APA

Никита Бобченок | Sciencx (2024-10-19T21:30:30+00:00) The list is not updated when adding a new item via useState(). Retrieved from https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/

MLA
" » The list is not updated when adding a new item via useState()." Никита Бобченок | Sciencx - Saturday October 19, 2024, https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/
HARVARD
Никита Бобченок | Sciencx Saturday October 19, 2024 » The list is not updated when adding a new item via useState()., viewed ,<https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/>
VANCOUVER
Никита Бобченок | Sciencx - » The list is not updated when adding a new item via useState(). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/
CHICAGO
" » The list is not updated when adding a new item via useState()." Никита Бобченок | Sciencx - Accessed . https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/
IEEE
" » The list is not updated when adding a new item via useState()." Никита Бобченок | Sciencx [Online]. Available: https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/. [Accessed: ]
rf:citation
» The list is not updated when adding a new item via useState() | Никита Бобченок | Sciencx | https://www.scien.cx/2024/10/19/the-list-is-not-updated-when-adding-a-new-item-via-usestate/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.