I'm creating a react app with a method to draw some arrows among divs. The function doesn't produce arrows right away returns the JSX but just after I manually re-render the DOM by scrolling the page or do a route change. How can I force render the DOM after the return of the function?
drawArrows = () => {
const questionsList = this.state.questionsData;
return questionsList.map(each =>
<Arrow
key={each.order}
fromSelector={`#option${each.order}`}
fromSide={'right'}
toSelector={`#q${each.order}`}
toSide={'left'}
color={'#ff6b00'}
stroke={3}
/>
);
}
render (){
return(
...code
{this.drawArrows()}
)
}
this.state.questionsDataa populated array when the component first renders? I don't see any issue with this code.drawArrowsfunction not to return JSX to be rendered. Are you sure it's populated at the time? Are you doing some state mutation elsewhere in the component? Can you provide a more complete component code example? Pretty much any time you get to a point where you think you need to "force react to render" you've done something wrong.