I have a HeadingComponent that shows page heading inside an h2 tag like so:
<div id="id1">
<h2 className="class1">{headingText}</h2>
</div>
This HeadingComponent is inside a parent div that has other components and divs embedded. ComponentThatDecidesHeading1, ComponentThatDecidesHeading2, ComponentThatDecidesHeading3 are the components that will decide what should be the {headingText} i.e.
<div id="layoutContentArea">
<HeadingComponent headingText={headingText}/>
<div or some wrapper component>
<ComponentThatDecidesHeading1/>
OR
<ComponentThatDecidesHeading2/>
OR
<ComponentThatDecidesHeading3/>
</div>
</div>
So, if ComponentThatDecidesHeading1 is rendered, headingText= 'Heading 1', if ComponentThatDecidesHeading2 is rendered, headingText = 'Heading 2' and so on.
Is there a way to put an "if" condition or something that checks which component is rendered and based on that display the corresponding headingText? Or Pass headingText from, , and fetch that in .
I checked ReactJS Two components communicating, Pass props to parent component in React.js, but didn't get my answer.
Any ideas?