I've passed a prop - {pov} to a component- Page I also have two other functional components - VisitorPOV and OwnerPOV if pov === 'visitor' , I want to render VisitorPOV Component else OwnerPOV Component Here is what I tried
function Page({pov})
{
return (
<div>
{ {pov} === "visitor" ? <VisitorPOV/> : <OwnerPOV/>}
</div>
);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
But what ever the prop is, it is only rendering false part ie. the component after :
Please help! Thanks
{}around the ternary so you are already in a JS expression context rather than jsx. So there is no need to enclose thepovvariable with an additional set of braces. In fact doing so creates an object withpovas the key name and the variable value as the value. Since objects are only equal via identity, this will always result in going down the "false" branch of your ternary. In short, just remove the curly braces surroundingpovin your ternary, and it should work.