Here is the scenario
Current Code:
componentDidUpdate () {
if (!isEqual(this.props.data, prevProps.data)) {
//logic
}
}
.......
export default connect(
state => {
return {
data: getData(state),
};
}, {
setData
},
)( localize(//classname) );
Problem:
In my case, sometimes, it may happen that there are 2 consecutive redux calls that will return the same data via selector. In that case the logic inside the componentDidUpdate will not work
Reason for having 2 consecutive same data values:
I have a list of questions in a data table and I can export this quetions on the basis of selection.
If I try to export the same question / same pair of questions consecutively, I will get same data for prevProps and current props.
Ex. Say, This is the list of questions in my data table.
1. Test Question 1
2. Test Question 2
Say, I am selecting the first question and then clicking on Export this will extract some data from database like Question, its answer, question type, etc. and this data will be returned from selector and then I am calling the logic (the one in componentDidUpdate) to create a file with this data and download it.
If I again select the first question and click Export then the data from selector will be exact same as the previous one. And I am not able to call "the logic" here.
(Calling this logic directly on componentDidUpdate will download file frequently, even when not supposed to)
Is there any way I can trigger the event every time selector gives me a value, irrespective of the previous value selector gave to me.
Thanks in advance.