Reputation: 33
Can I do something like this in React inside a component? I am quite sure that I can but still do not know how exactly. What I want is to set post.summary to null or empty and I also need an else case like if it is not team_member value should be post.summary.
<my_component
value={post.summary = post.type === "team_member" ? "null" : "null"}
/>
Thank you in advance!
Cheers
Upvotes: 0
Views: 37
Reputation: 739
If you are more specific about your requirements, we can address it accordingly.
Howerver,
If you want to pass some value as prop after evaluating a condition, you can.
<Component
value={condition === 1 ? "Yes" : "No"}
/>
The meaning here is, if the condition is satisfied, value prop will be "Yes" else "No".
If you want to conditionally put some content in your component. Sure, you can.
Solution 1
<Component>
{condition === 1 ? <div>Yes</div> : <div>Nope</div>}
</Component>
Solution 2
<Component>
{condition === 1 ? "Yes" : "Nope"}
</Component>
Solution 1 demonstrates that you can put another component or html tag
Solution 2 says that it can be a simple string too.
Hope it helps :)
Cheers,
Kruthika
Upvotes: 1