Created
January 18, 2020 14:16
-
-
Save lior-amsalem/2c3a9badcd88a4ea76bcf7b23ca51b52 to your computer and use it in GitHub Desktop.
Dynamically generated inputs - part 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderList() { | |
const { | |
catList, | |
showNewField, | |
} = this.state; | |
const nextIndex = catList.length; | |
const listOfCustomHeaderField = catList.map((cat, index) => [ | |
<React.Fragment key={cat.generateKey}> | |
<div className="Rtable-cell"> | |
<input | |
type="text" | |
value={this.getCatDataSafely(index, 'catName')} | |
onChange={this.handleChangeOfCatDataFactory('catName', index, cat.generateKey)} | |
/> | |
</div> | |
<div className="Rtable-cell"> | |
<input | |
type="text" | |
value={this.getCatDataSafely(index, 'catAge')} | |
onChange={this.handleChangeOfCatDataFactory('catAge', index, cat.generateKey)} | |
/> | |
<FontAwesomeIcon icon={faMinusCircle} className="icon-delete-wrapper" onClick={() => this.deleteCustomHeader(index)} /> | |
</div> | |
</React.Fragment> | |
]); | |
// do we need to add additional new empty row? | |
if (showNewField) { | |
const generateKey = this.generateKey(1, 100000); | |
listOfCustomHeaderField.push([ | |
<React.Fragment key={generateKey}> | |
<div className="Rtable-cell"> | |
<input | |
type="text" | |
value={this.getCatDataSafely(nextIndex, 'catName')} | |
onChange={this.handleChangeOfCatDataFactory('catName', nextIndex, generateKey)} | |
placeholder="Enter a cat name" | |
/> | |
</div> | |
<div className="Rtable-cell"> | |
<input | |
type="text" | |
value={this.getCatDataSafely(nextIndex, 'catAge')} | |
onChange={this.handleChangeOfCatDataFactory('catAge', nextIndex, generateKey)} | |
placeholder="Enter a cat age" | |
/> | |
</div> | |
</React.Fragment> | |
]); | |
} | |
return listOfCustomHeaderField; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment