- I am using "reselect" library in redux to get the data. I wanna get data based on
useParams()
hook and then to pass it insidemapStatetoProps
asownProps
and then toselectionCollection
function which is a selector and accepts the value ofuseParams()
. Apparently, it doesn't recognize theuseParams()
asownProps
and eventually returns undefined. btw, If I pass a string insideselectionCollection('someString)
, I receive the data but not usinguseParams()
hook. I do receive theuseParams value successfully
but can't use it insidemapStateToProps
which I think is a scope problem. I did define a global variable but didn't work.
import { connect } from 'react-redux';
.
import { Outlet, useParams } from 'react-router-dom';
import { selectCollection } from '../../redux/shop/Shop-selectors';
const CollectionPage = ({ collection }) => {
const params = useParams();
const paramsId = params.collectionId;
console.log(collection);
return (
<div className="collection-page">
<p>THis is the collection page for {paramsId}</p>
<Outlet />
</div>
);
};
//-- If I log the 'paramsId', I get undefined since it's outside the function
const mapStateToProps = (state, ownProps) => ({
// here is where I wanna use the paramsId as ownProps
collection: selectCollection(ownProps.paramsId)(state),
});
export default connect(mapStateToProps)(CollectionPage);