I have a slice in my store I created with createEntityAdapter from Redux Toolkit. In Function components you can use useSelector with the selectors returned from adapter.getSelectors().
But how can I get all entities as an array (like with the selectAll selector) in a class based component? I am using connect with mapStateToProps, which just allows me to get either entities or ids as a prop, but not all entities as an array sorted in the same order as the ids are sorted...
You would use the same selectAll selector, but you would call it in your mapState function for use with connect instead of passing it to useSelector:
const mapState = (state) => {
return {
items: itemsSelectors.selectAll(state)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With