I have a div
where inside another three div
s are appending as follows. The state values are setting by looping the result from an api from componentWillReceiveProps()
. But I'm facing an issue with an error
Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node
and if the api result is null gets
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
How can I fix this?
componentWillReceiveProps(nextProps) {
var sub1 = [], sub2 = [], sub3 = [];
if(result) {
result.sub1.map((item, index) => {
sub1.push(
<div>
<p>{item.name}</p>
</div>
)
})
result.sub2.map((item, index) => {
sub2.push(
<div>
<p>{item.name}</p>
</div>
)
})
result.sub3.map((item, index) => {
sub3.push(
<div>
<p>{item.name}</p>
</div>
)
})
this.setState({ subDiv1:sub1, subDiv2:sub2, subDiv3:sub3 })
}
}
render() {
return(
<div className="row top_bar">
<div className="search left col-xs-5 col-sm-4 col-md-5 col-lg-6">
<form>
<input type="text" id="search_box" name="search_box" placeholder="Search" onKeyUp={this.keyUpFn} />
</form>
<div className="div1">
{ this.state.subDiv1 }
{ this.state.subDiv2 }
{ this.state.subDiv3 }
</div>
</div>
<div className="top_right col-xs-7 col-sm-8 col-md-7 col-lg-6">
<div className="top_outer">
</div>
</div>
</div>
)
}
insertbefore
should be used somewhere. I don't know where to use it. Do you have any idea? – ToninacomponentWillReceiveProps
and use state value inside the render method ? – ToninacomponentWillReceiveProps
in your code. Yes, it's probably wrong, but I can't say what's the right way because I don't know what you're trying to do. Typically you shouldn't need to put JSX outside the render method. – Paymarresult
? – Paymarrender
? – Paymardiv
parallel to the main div inside render. But I couldn't find a solution for this and I'm stuck with this. Will be helpful if you could help me – Tonina