I would like to get the user's consent with a click on a banner button before I use LocalStorage. LocalStorage is used through redux-persist
. I'm using redux
and redux-persist
as follows:
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persitor} >
<MyAppRouter />
</PersistGate>
</Provider>,
document.getElementById("root")
)
and store
and persistor
are coming from
import { createStore } from "redux"
import { persistStore, persistReducer } from "redux-persist"
import storage from "redux-persist/lib/storage"
import { rootReducer } from "../reducers/index"
const persistConfig = {
key: "root",
storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
const store = createStore(persistedReducer)
const persistor = persistStore(store as any)
// `as any` is necessary as long as https://github.com/reduxjs/redux/issues/2709 is not fixed
export { store, persistor }
redux-persist
persists the initial state in LocalStorage as soon as the objects are created which is not what I want.
I'd like to use redux in my React components no matter whether the state is persisted or not.
I assume the details of the reducer don't matter as it doesn't have influence on where/how the state is stored.
The information that the user once has expressed consent to use LocalStorage and cookies is stored in a cookie.
How could I start using LocalStorage for persistence only after the user has expressed consent during the first visit or if the cookie is present already? The case that the cookie expired or has been deleted should be covered by the case of the first visit.
In order to minimize discussion I'm looking for a solution which solves the technical problem. The request might be overkill in terms of legal requirements.
Things I tried so far:
- Use two store (probably bad practice) which are managed in the state of an
App
component which wrapsProvider
as shown in the example. Problem is that the page is re-rendered as soon as the banner button is clicked which is not acceptable. - Evaluated blacklisting which won't work because it has no impact on the initial persistence of the state.
[1] https://softwareengineering.stackexchange.com/questions/290566/is-localstorage-under-the-cookie-law