I have two functions that both set different values. In the markup, how do I set the attribute to have the correct spread. I know how to do this with the standard ternary operator but I don't want to copy the same code for everything that goes under the attribute, as it's wrapped inside of it.
const labelAttributes = ['checkbox'].includes(type)
? keyboardEvents({ space: () => helpers.setValue(!field.value) })
: null;
const labelAttributesRadio = ['radio'].includes(type)
? keyboardEvents({ space: () => helpers.setValue(value) })
: null;
return (
{type == 'radio' ? (
<label {...labelAttributesRadio}>
) : (
<label {...labelAttributes}>
)}
// Removed a lot more content but don't want to have to copy it twice within the operator
<Field>
</Field>
<span>
</span>
</label>
)