In my application, I want to pass the parameter that I'm getting from useParams()
to the mapStateToProps
function which I'm using with the Reselect library.
I can hard code the value instead of passing this parameter and everything works as expected. Also, I can pass useParams().routeName
directly to the mapState
function and it's working. But in case of using ownProps
, it is not working. Here is my code:
const CollectionPage = ({collection}) => {
let params = useParams();
let collectionPath = params.routeName;
return (
<div className='collection-page'>
</div>
)
}
const mapStateToProps = (state, ownProps) => ({
collection: selectCollection(ownProps.collectionPath)(state)
});
export default connect(mapStateToProps)(CollectionPage);
With this code, the return will be undefined, but when I hard code the value, like the code below, it’s working:
const mapStateToProps = (state) => ({
collection: selectCollection(''Some Hard Coded Value'')(state)
});