I am having an array "personArray" in the state of my react component. I have a search bar in the component. Based on what I type in search bar, I make a request to an api and update the state of "personArray". I mapping this "personArray" in my render method. (see code below)
Problem: When I type the first letter in the search bar, the list of people gets updated and reflects in render properly. When as soon as I type the second letter, I get this error saying
Uncaught DOMException: Failed to execute 'removeChild' on 'Node':
The node to be removed is not a child of this node.
Code:
THis is my search bar
<input type="text" className="input-hidden" placeholder="search" ref="personSearch" id="personSearch" onChange={()=>{this.searchForPerson()}}>
This is the searchForPerson function (here I search and update my state)
searchForPerson(){
var that = this
let req = fetch(url,
{
method: "GET",
headers: {
"Authorization": "Token " + this.props.token_reducer.token,
"content-type": "application/json"
}
})
req.then(response => response.json()
).then(response => {
console.log("type it")
console.log(response)
that.setState({ personArray: response.results }, () => {
//new SimpleBar(document.getElementById('items-listing'))
console.log(this.state.personArray)
})
})
}
This is my where I map "personArray"
<div className="items-listing" id="items-listing">
{this.state.personArray && this.state.personArray.map((item, i) => { return
<div className={`item ${this.state.activePersonRow===i
? "active" : ""}`} key={i} onClick={()=> { this.onPersonRowClick(i, item.name, item.id) }}>
<div className="item-img" style={{backgroundImage:`url(${item.personframes.length !==0 ? item.personframes[0].file : ""})`}}></div>
<div className="item-title">{item.name}
<br/>
<div className="item-sub">{item.occupation}</div>
</div>
<div className="item-count">{item.personframes.length}</div>
</div>
})}
</div>
UPDATE: I observed something. When the api returns equal to or more than 10 items array then it works. As soon as api return an array with less than 10 items then the error comes. No idea why but this is the case. –