When I am comparing two arrays from my state, if they are equal I want to change a third state boolean variable to "true". However when the two arrays are equal, the if statement I created to detect it does not return a "true".
I am doing this within a setInterval(), i dont know if that has anything to do with this problem...
class DisplaySort extends Component {
constructor(props) {
super(props);
this.state = {
array: [1, 2, 3],
array2: [1, 2, 3],
istrue: false,
};
this.compare = this.compare.bind(this);
};
render() {
return (
<div>
<button onClick={this.compare}>Compare</button>
</div>
);
}
compare(e) {
this.myInterval = setInterval(() => {
let a = this.state.array.slice();
let b = this.state.array2.slice();
if (a === b) {
this.setState({ istrue: true });
clearInterval(this.myInterval);
}
(The set interval is being used for another operation in the application (aka there is an else statement after the if) but excluded for brevity's sake)