reactjs - redux: how to access dispatch from selectors

Viewed 3172

I have a situation like below:

state = {
     items: [.....list of items]
     filteredcount: count of filtered items done by selector
}

I have a component with the following code to pass state properties.

const mapStateToProps = (state,ownProps) => {
    return {
        items: getItems(state.items,ownProps.condition),
        filteredcount: state.filteredcount
    }

Inside the getItems selector i want to dispatch an action to update the filteredcount.

const getItems = (results,condition){
    filteredresults = ...filter results here based on condition
    dispatch(updatenumber(filteredresults.length))
    return filteredresults
}

where updatenumber is an action creator to update the state.filteredcount

How to do this

0 Answers
Related