Whenever the specific show more
button is clicked, the content should be displayed without causing the entire component to re-render. I have tried using a useState
, but each time the button
is clicked, the whole component re-renders, resulting in long loading times for every div. Is there a simple solution to avoid this issue?
const [arr,setmarr] =useState([])
const oncl=(e)=>{
setarr((prev)=>[...prev,e.target.value])
}
return{
divarray.map((i,j)=>{
{console.log("tdic)")}
return(
<Commentbox divarr={arr[j]} value={j} oncl={(e)=>oncl(e) } />
)
}
}
Commentbox component
return
<div>
div{j}
// some icons here
{divarr && <div> right side div </div>}
<button onClick={(e)=>{oncl(e)}} value={j} >see more</button >
</div>
prior to clicking showmore
https://i.sstatic.net/PyV11.png
upon clicking the showmore
button on the second div
https://i.sstatic.net/HLKaF.png