I have the following component:
function Params(props) {
const { Parameters } = useFetchParams();
return (
<div className='Params'>
{
Parameters && Parameters.map(parameter => {
const { Name, Value } = parameter;
if (Name.includes(props.filter)) {
return (
<div className='Param' key={Name}>
<p>{Name}</p>
<p>{Value}</p>
</div>
)
}
})
}
</div>
)
}
I want to only display "Parameters" that include the text I'm passing in from props. You can see I'm currently using an if statement for this, and it seems clunky. I'm wondering if it's possible to map and filter over this array at the same time.
I've tried sticking filter at the end of the map but it returns an error.
Thanks for looking
.filter()you may still use a single.map()that returns conditionally either your JSX ornull/false/undefinedthat will get ignored on render.reduce. It can do both of those at the same time.