Skip to content

Local storage - x-data showing old/wrong value after page refresh #1210

Answered by SimoTod
DarpanKulkarni asked this question in 1. Help
Discussion options

You must be logged in to vote

localStorage saves and retrieves everything as strings. The string false is a truthy value so it works as expected.
You need to change your x-data to x-data="{darkMode: localStorage.getItem('dark') === 'true'}"

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@DarpanKulkarni
Comment options

Answer selected by DarpanKulkarni
Comment options

You must be logged in to vote
1 reply
@ekwoka
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants