How to pass an additional argument to useSelector

unfortunately, selector function accepts only store’s state as argument. I would consider to use a currying approach to tackle the issue: export const getProductNameById = id => store => { return store.dashboard.dashboards.filter(({ Id }) => Id === id)[0] .Name; } some file import { useSelector } from “react-redux”; import { getProductNameById } from “./selectors”; const … Read more

Why use redux-thunk? [duplicate]

Redux Thunk teaches Redux to recognize special kinds of actions that are in fact functions. When an action creator returns a function, that function will get executed by the Redux Thunk middleware. This function doesn’t need to be pure; it is thus allowed to have side effects, including executing asynchronous API calls. The function can … Read more

react-redux-v6: withRef is removed. To access the wrapped instance, use a ref on the connected component

You need to replace withRef with forwardRef as per the release notes: The withRef option to connect has been replaced with forwardRef. If {forwardRef : true} has been passed to connect, adding a ref to the connected wrapper component will actually return the instance of the wrapped component. So in your case: export default connect( … 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

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