score:1
Accepted answer
that's because your getcountrybyid
isn't actually a selector. it's a function that returns a selector.
given that you are trying to use a unique id per component, and doing filtering, you probably need to use the "factory function" form of mapstate
to create a unique selector instance per component instance to get proper memoization behavior.
however, having said that, your selector can also be simplified. you don't need a filter()
here, you need a find()
, and that means it's also not something that really needs to be memoized. this can be simplified down to:
const getcountrybyid = createselector(
[getcountries, (state, id) => id],
(countries, id) => countries.find(c => c.id === id) || null
)
and then used as:
const mapstatetoprops = (state, ownprops) => {
return {
country: getcountrybyid(state, ownprops.match.params.countryid)
}
};
Source: stackoverflow.com
Related Query
- Redux Selector not called
- Redux - reducer not getting called
- Redux Selector not triggering when I'm calling it from mapstatetoprops
- Redux reducer not being called
- ComponentDidMount not getting called after redux state update?
- Change in redux state does not cause change in component / componentDidUpdate not called
- How to properly initialize React app with redux in Cordova - mapStateToProps not called
- Redux Thunk + ReactJS: Action creator being called but dispatch function not being called
- redux selector is not filtering nested array accordingly
- Redux mapDispacthToProps - prop not invoked when called from unload event
- Redux Thunk Action Creator Not Getting Called
- redux connect mapStateToProps not called when action is dispatched
- Can't get Redux (Thunks) to work with NextJS using next-redux-wrapper: getInitalProps not called
- React Redux : use Selector is called before dispatch
- Reducer not being called in my Redux setup
- Selector data is loaded correctly from the redux store, but not displayed by the calling page component
- applying middleware on store is not called reducer correctly in Redux
- Update: Redux reducer is not beeing called to change CSS classes
- Redux is not returning data from reducer after action is called
- Props not being updated when Redux action is called
- Redux Saga not triggered/api not called - props undefined
- Actions passed as props in Redux connected component are not called when form submit is simulated during testing
- Redux reducers not being called when using dispatch() in Component
- Redux Selector function returns error if not named correctly
- Redux reducer is not getting called in React app using react-redux hooks
- Why is my redux selector not behaving correctly?
- Redux - Reducer is not being called when I dispatch an action
- Redux toolkit axios api is not getting called
- Reducer not receiving action in redux or trouble with the action being called
- React useEffect Hook not called after redux State Change
More Query from same tag
- Errors while Using map functions in React
- New to TypeScript, what does this chunk of code do?
- React + Redux + Typescript Chrome Extension Popup Script - Redux Devtools Shows "No Store Found"
- Delete item with redux
- After concat the page scrolls back to the top
- How to correctly implement the delete functionality in React Redux
- React.js setting value of input
- What is the simplest way of testing that a React Component contains a html node with enzyme?
- How to find the positions and width/heights of react components?
- If there are two counter components to be tied to two properties in the Redux Store, do you have to write reducer, mapStateToProps, etc, twice?
- Reactjs add a number to a state?
- React jsx not returning my button in async function
- When the amount is not in USD currency don't have the $ symbol in the front
- React, Formik, Yup: How to register touch when using calendar picker
- How to replace space with in a string (ReactJS) and render in HTML?
- Redux-i18n accessing t() function outside React components, e.g. in action creators
- Setting state issue in react
- How to fix unique "key" prop and validateDOMNesting(...) in ReactJS with fuctional component
- Handling event method with parameter without inserting parameter
- Checkbox toggle is not working properly in react.js
- React Infinity scrool : TypeError: Cannot read property 'offsetTop' of null
- How to append an object id and name to form data in React?
- Acces this.state variables in React
- How Redirect when a Promise is Resolved?
- React - Linear Gradient Inline Style vendor prefixes
- How to actually use context?
- Change color of button inside active NavLink (React)
- How to pass react useState hook from parent to Child components
- How to initiate state based on certain props
- Method onChange just get the last array value