I have a component that needs to load a certain item according to a props it receives from the parent component.
const Contract = ({ savingsFactors, isContract }) => (
{isContract ? (
<PutField
label={label}
placeholder={placeholder}
onBlur={...}
items={savingsFactors === 'true' ? FORM_VALUES : FORM_VALUES_NORMAL}
/>
) : (
<PutField
label={label}
placeholder={placeholder}
onBlur={...}
items={savingsFactors === 'true' ? ANOTHER_FORM_VALUES : ANOTHER_FORM_VALUES_NORMAL}
/>
)}
);
The only thing that changes is the values inside the items.
These values are objects with arrays:
const FORM_VALUES = [
{ name: 'some name', value 'some value' },
{ name: 'some name', value 'some value' },
]
const FORM_VALUES_NORMAL = [
{ name: 'some name', value 'some value' },
{ name: 'some name', value 'some value' },
]
const ANOTHER_FORM_VALUES = [
{ name: 'some name', value 'some value' },
{ name: 'some name', value 'some value' },
]
const ANOTHER_FORM_VALUES_NORMAL = [
{ name: 'some name', value 'some value' }
]
Is there any way I don't need to repeat these two blocks of code?
itemsprop?itemsabove the component, figure out what it needs to be then pass ititems={items}