-1
I need to send a request, but there is a parameter that is optional, and I must only send it on one condition. It’s like this:
const [blocoSelect, setBlocoSelect] = useState("nenhum");
params: {
initial_date: dateRange.startDate._d,
final_date: dateRange.endDate._d,
order: isMaisAntigasSelected ? 'DESC' : 'ASC',
condo_id: condoSelect,
blocs: isManuBlocs,
areas: isManuArea,
// bloc_name: opcional
}
That one bloc_name is optional, it will only get mine blocoSelect unlike any other, I tried something like:
params: {
initial_date: dateRange.startDate._d,
final_date: dateRange.endDate._d,
order: isMaisAntigasSelected ? 'DESC' : 'ASC',
condo_id: condoSelect,
blocs: isManuBlocs,
areas: isManuArea,
{
blocoSelect!=="nenhum" &&
bloc_name: opcional }
}
But I saw that the syntax was wrong and I don’t know how to fix it