I have 2 files Server.js and Servicedesk.js, I work with socket.io and ReactJS. I want to compare an array from Server.js (my socket.io file) with an array from Servicedesk.js. In Servicedesk.js I have the following code:
class Servicedesk extends React.Component {
constructor(props) {
super(props);
this.state = {
messages: [],
};
socket.on('updateRooms', function(combMessages) {
console.log(combMessages.length);
console.log(this.state.messages.length);
let intersection = combMessages.filter(x => this.state.messages.includes(x));
console.log(intersection);
});
}
}
And in Server.js:
let combMessages = [];
I'm passing the combMessages to the Servicedesk.js but how can I compare both? Because I can't do something like:
let intersection = combMessages.filter(x => this.state.messages.includes(x));
Because I'm getting this error:
TypeError: undefined is not an object (evaluating 'this.state.messages')
lambdafunction passed as parameter tocombMessages.filter()cannot "find" thethis.state.messages, and that's tem reason to the error given