Redux vs plain React [closed]

Off the top of my head, a few advantages: A lot of the time your app’s state tree could be considerably different than the UI tree Many components may need to access the same state and display it in different ways Hot reloading components will wipe out your existing component tree, including any state stored … Read more

How can I use react-redux useSelector in class component?

As @Ying Zuo said, your method works only with Functional Components. To solve this problem: Instead of this line: const counter = useSelector(state => state.counter); You define the counter state like this: const mapStateToProps = state => ({ counter: state.counter }); Then for dispatching you should use it like this: const mapDispatchToProps = () => … Read more

TypeError: middleware is not a function

According to the docs you are mixing up the usage of redux-logger You either need to import the specific createLogger function import { createLogger } from ‘redux-logger’ const logger = createLogger({ // …options }); Or use the default import import logger from ‘redux-logger’ And then your code should be fine const store = createStore( reducers, … Read more

React require(“history”).createBrowserHistory` instead of `require(“history/createBrowserHistory”)

Import creatBrowserHistory with curly brackets. It’s exported as a named export. // history.js import { createBrowserHistory } from “history”; export default createBrowserHistory(); Then import and use it in index. // index.js import history from “./history”; import { Provider } from “react-redux”; import store from “./store/store”; const AppContainer = () => ( <Router history={history}> <Provider store={store}> … Read more

Flow: Throws error Cannot resolve module “react-redux” even tho it’s installed

How to fix it You have two options: stub the dependency by hand bring in flow-typed to find the dependency type file/stub it for you I use option 2 but it is nice to know what is happening underneath Option 1 In .flowconfig, add a directory under [libs], … [libs] /type-def-libs … Now, create that … Read more

Accessing a part of reducer state from one reducer within another reducer

This is covered in the Redux FAQ at https://redux.js.org/faq/reducers#how-do-i-share-state-between-two-reducers-do-i-have-to-use-combinereducers: Many users later want to try to share data between two reducers, but find that combineReducers does not allow them to do so. There are several approaches that can be used: If a reducer needs to know data from another slice of state, the state tree … Read more

connectedRouter Error: Could not find router reducer in state tree, it must be mounted under “router”

For the sake of helping future souls with this issue, it turns out that according to the linked github discussions, that version 5.0 of the history package is causing the issue and downgrading to version 4.10.1 solves the problem for me. npm install history@4.10.1 https://github.com/ReactTraining/history/issues/803 https://github.com/ReactTraining/history/issues/804