Discussion: Question (used libs)
@jdiefenbaugh : Could you explain to me this part please ?
renderLibraries = () => (
<TabPane tabId='2'>
<Row>
<Col sm='12'>
{
// loop through all the used libs
(Object.entries(this.props.data.contents.uses): [string, any][])
.map(([name, lib], i, lEntries) => (
<TypedField
key={i}
name={name}
type={lib}
types={this.props.libraries.map(l => l.name)}
existingFields={lEntries.map(([n, v]) => n)}
nameUpdateFunc={str => {
// update the alias
this.changeContentsVal('uses',
changeObjFieldName(
this.props.data.contents.uses,
name,
str
)
);
}}
typeUpdateFunc={str => {
// update the chosen library for the alias
const libs = {
...this.props.data.contents.uses,
[name]: str
};
this.changeContentsVal('uses', libs);
}}
deleteFunc={() => {
const libs = { ...this.props.data.contents.uses };
delete libs[name];
this.changeContentsVal('uses', libs);
}}
/>
))
}
</Col>
</Row>
<Button outline block
id='newLibraryBtn'
onClick={() => {
const newKey = generateNewKey('library', Object.keys(this.props.data.contents.uses));
this.changeContentsVal('uses',
{
...this.props.data.contents.uses,
[newKey]: ''
}
);
}}
>
New Library
</Button>
</TabPane>
);
What actually interests me is what is inside the loop (// loop through all the used libs)
Could you explain to me a bit please and point me to some documentation you read to write this kind of stuff?
Thanks