Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get entities as an array in a class component when using createEntityAdapter from Redux toolkit?

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...

like image 792
Christoph Hummler Avatar asked Dec 06 '25 04:12

Christoph Hummler


1 Answers

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)
  }
}
like image 163
markerikson Avatar answered Dec 07 '25 18:12

markerikson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!