A
A
alex4answ2020-12-15 16:55:16
redux
alex4answ, 2020-12-15 16:55:16

Is it possible to use hooks to set the initialState of redux?

Good afternoon, I ran into this issue.

In the Redux Store I store which theme to use (dark or light)

Is it possible to use hooks, queries in the initialState for the reducer?
For example, to determine the current theme, I need to perform the following actions:

  1. If there is a localStorage theme, then take it
  2. If media query - "prefers-color-scheme: dark" true then set dark theme
  3. Otherwise - light theme


Or are there only literal values ​​in initialState, and all side effects, requests, etc., etc., should be in the component, and dispatched from useEffect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex4answ, 2020-12-17
@alex4answ

initalState must be synchronous so that synchronous operations can be performed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question