Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

how to get previous state value to compare with current state value under middleware?

$
0
0

I am new to redux and I would like to create a middleware to get the number variable from previous state and current state then compare the numberif the value of number is the same, it would not call the useSelector(action). I use getState under async that I can get current state value. However, how can I get previous state value? I do not want to use mapStateToProps as I only want to create some function to help me to achieve the compare logic

export const shouldSetNumber = () => {  return async (dispatch, getState) => {    const current = getState()?.number || 0;    console.log(current);    useSelector(setNewNumber(current))  };};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>