trying to do a nested if statement or if else if statement in jsx. essentially if there is 1 input it has the label of Primary, if there are 2 inputs, the first one has label primary and second one has label of Secondary and if there are more than 2 the first has label as Primary, second as Secondary and 3 going forward have no label.
Currently my code puts label Primary on the first and Secondary on the second but as soon as I add a third it erases all labels. Any ideas would be awesome.
render() {
const { lowerType, currentPerson, contact, index, type } = this.props;
const isPrimary = index === currentPerson.getIn(['primaries', lowerType]);
// const secondaryLabel = <label><b>Secondary</b></label>;
const label = <label><b>{ isPrimary ? 'Primary' : 'Secondary' }</b></label>;
return (
<div className='field main-item'>
{ currentPerson.get(`${lowerType}s`).size <= 2 && label }
<Input
value={contact}
onChange={this.handleInputChange}
placeholder={`Enter ${type === 'Email' ? 'an' : 'a'} ${type.toLowerCase()}`}
type={type === 'Email' ? 'text' : 'tel'}
style={inputRight}
/>
</div>
);
}
const label = <label><b>{ isPrimary ? 'Primary' : 'Secondary' }</b></label>; return ( <div className='field main-item'> { currentPerson.get(${lowerType}s).size <= 2 && label }