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

standard redux template comes with redux toolkit and that comes with reselect. here are some examples of how to create composable memoized selectors.


Related Query

More Query from same tag