我收到一个来自 的 url 参数useParams。我想使用将它传递给选择器mapStateToProps。
集合.组件.jsx
import { useParams } from "react-router-dom";
import { connect } from "react-redux";
import { selectShopCollection } from "../../redux/shop/shop.selectors";
import './collection.styles.scss'
const Collection = ({ collection }) => {
const { collectionId } = useParams();
console.log(collection)
return (
<div>
<h1>{collection}</h1>
</div>
)
}
const mapStateToProps = (state, ownProps) => ({
collection: selectShopCollection(ownProps.match.params.collectionId)(state)
})
export default connect(mapStateToProps)(Collection);
Run Code Online (Sandbox Code Playgroud)
shop.selectors.js
import { createSelector } from "reselect"
const selectShop = state => state.shop
export const selectShopCollections …Run Code Online (Sandbox Code Playgroud) reactjs reselect react-router-dom react-hooks mapstatetoprops