score:4
Accepted answer
you can pass arrow function in useselector
export const countyselector = state => {
const id = state.user.id;
const name = state.user.name;
return state.users.find(user => user.name === name).county;
};
// usage
import { countyselector } from 'selectors';
const county = useselector(countyselector);
or create custom hook
const usecounty = () => {
return useselector(state => {
const id = state.user.id;
const name = state.user.name;
return state.users.find(user => user.name === name).county;
});
};
export default usecounty;
// usage
import usecounty from 'usecounty';
const county = usecounty();
score:2
Source: stackoverflow.com
Related Query
- react redux using useSelector multiple times in app
- What happens when using this.setState multiple times in React component?
- How to create multiple page app using react
- React Native - Redux : Multiple instances of same state in app
- Using OAuth2 refresh token in React Redux app
- using multiple redux stores one for each app user
- React Redux app structure multiple roles
- How to manage React Js to multiple page app not using routes?
- How can I render the react app with redux using the ReactJS.NET?
- Using ref react hooks multiple times
- Props mix when using the same component multiple times on a page in React
- Aborted request using AbortController in React Redux app is aborted forever
- Using Redux default store from window in React app
- How to update state multiple times on same event using React useState hook?
- How do you replace data multiple times with an array of keys using a react hook?
- Build react app multiple times with different environment variables
- Using React useEffect in a loop to fetch data from an API multiple times
- How do I use Redux Toolkit with multiple React App instances?
- Redux reducer is not getting called in React app using react-redux hooks
- Using Redux-Saga in New Redux template react app
- Express server doesn't respond correctly when hosted in a remote server, as I am using React Redux locally to get data of Express app remotely
- Using redux with Nextjs I don't understand why it requires more setup different than react app
- How to call same query multiple times using apollo client in react js on first mount
- Trying to Call Multiple ActionCreators in Component using React Redux and Typescript
- How can I update react app that gets it's data from the node mongo backend using redux
- Using React in a multi-page app
- How to show a loading indicator in React Redux app while fetching the data?
- Using API keys in a react app
- Cheapest way to deploy a React app using NextJS SSR on AWS?
- React component render is called multiple times when pushing new URL
More Query from same tag
- How to map an array of map in react?
- react pdf multi lines puts all lines in one line
- How to pop out custom modal when leaving or refreshing the page?
- How to make a loop to reuse a function
- Right way of implementing a modal in React
- Passing props in map function doesn't work. Passing it as key works
- ReactJS - Warning: Unknown prop
- React recursively call method on children
- _this3 not a function (React)
- firebase google authentication with token
- Preact: Typing the props of a component that wraps a native component
- Devise DELETE /users/sign_out returns status 204 and doesn't redirect?
- How to send conditional props from Parent to Child. (send if only array is not empty)
- Reactjs object data showing undefined even after showing data in console.log
- How to implement the actions queue in a flux app
- How to export ReactJS app as package to be used in other app?
- unhandledRejection: TypeError: Cannot destructure property 'protocol' of 'window.location' as it is undefined
- ReactJs: How to properly recieve server request
- React axios file upload failing - error "Multipart: Boundary not found"
- Getting dimensions of all children elements
- How to reset the value of antd autocomplete, if the value is not in the data source
- how can I change the layout of this material UI form?
- Use `ListBox` from `@headlessui/react` with Mobx?
- add multiple node box selector on the canvas of VisJS network graph in ReactJS
- Code meant for form validation success running even when validation fails
- How to properly serialize query params?
- react router and routes is not working , i could not able to navigate to blogs page
- Next Image, image disappears with layout responsive
- I get the error : - Unhandled Rejection (TypeError): Cannot read property 'id' of undefined in React Application
- Use flexslider jQuery plugin in React