Skip to content
Advertisement

Persisting select option on page refresh React Remix

I have a select with 2 options (en, no), which switches the language onChange.

I store selected language to localStorage. Because I’m using Remix I cannot simply access localStorage, because of the server-side rendering, so I’m using:

JavaScript

Select component:

JavaScript

Translation function:

JavaScript

My goal is to have selected option saved and persistent on page refresh, now when I refresh the page, it gets reseted to NO (Norwegian)

Advertisement

Answer

I guess you can solve this by giving value attribute instead of defaultValue.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement