Is it possible to write a conditional render with an OR operator in the statement? to avoid double code.
{regions && || regionsWithAnimals && (
<>
<h4>Title</h4>
<div>
<RegionsMap
regions={regions || regionsWithAnimals.regions }
/>
</div>
</>
)}
Something like this, this is not working of course
EDIT: I could write:
{regions && (
<>
<h4>Title</h4>
<div>
<RegionsMap
regions={regions }
/>
</div>
</>
)}
and below:
{regionsWithAnimals && (
<>
<h4>Title</h4>
<div>
<RegionsMap
regions={regionsWithAnimals.regions }
/>
</div>
</>
)}
This is what I want to achieve, but I'm calling two times the same component.
(regions || regionsWithAnimals) && ...Though I should point out in your example if both are true they each render, but what you describe you want is for one or the other to render. Just keep the conditions in the same order in the component.Type '{ name: string; path: string; }[] | undefined' is not assignable to type 'regions'. Type 'undefined' is not assignable to type '{ name: string; path: string; }[]'.By defining the props 'regions'.