简体   繁体   中英

React js remove third party rendered html

I have below code

<div id="parent">
<div id="dvWeather">
{
data && (
thirdparty.renderWeatherInfo(data,"dvWeather")
)
}
<div/>
</div>

What it does

<div id="parent">
<div id="dvWeather">
<div id="mtWeather">
other stuff
</div>
<div/>
</div>

So it is working when it data has value, but when I update the data with state to null, it renders but the content of dvWeather does not remove.

But when I do simply this

<div id="parent">
<div id="dvWeather">
{
data && (
<h2>Hello</h2>
) 
}
<div/>
</div>

I can see when data is not null h2 is rendering, if null then blank

Third party is using react react dom to render component in given div

I believe this because dvWeather has been rendered by different reactjs state, so in my project state unable to remove it

What could be the possible issue and work around it

Thanks

Maybe you can try this way

<div id="parent">
<div id="dvWeather">
{
data ? (
thirdparty.renderWeatherInfo(data,"dvWeather")
) : null
}
<div/>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM