How do I clear states or empty array on click in react 0.14 ES6?
I found the problem is my closeModal didn’t get called at all on closing modal. I am doing that to closeModal on componentWillUnmount function. I understood that the below code causes problem.
this.state.myArray=[] // class component
const[myArray, setMyArray]=useState([]) // functional component
I changed it back to
this.setState({myArray: []}); // class component
setMyArray([]); // functional component
You can as well use this to clear array without using setState:
this.state.your_array.length = 0;
This will work in any function.