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 productId = 25;
const productName = useSelector(getProductNameById(productId));
Seems like the way to do this would be like this:
const productName = useSelector((state) => getProductNameById(state, productId));
This is the how redux docs tutorial seems to handle this. here