DEV Community

Shivani Bali
Shivani Bali

Posted on

Remove multiple div's in reactJS

Hi,

I am trying to remove the multiple div's generated via the add button.
I'm having trouble in understanding how can I send the parent div's id into delete method passed from the child div. Also, if I can store the div's id into a state to perform deletion process. My code is as follows. I appreciate your inputs and suggestions.

constructor(props) {
super(props);
this.state = {
names: [],
inputValue: '',
id: [],
count: 1,
hostname: '',
devname: '',
sellID: '',
}
this.addRow = this.addRow.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.deleteRow = this.deleteRow.bind(this)
}

addRow() {
this.setState({ count: this.state.count + 1 })
console.log(Increase count: ${this.state.count})
};

renderDivs() {
let count = this.state.count, uiItems = [];
var { names } = this.state;
let options2 = names.map(name2 => {
return { value: name2.name, label: name2.name };
})
while (count--)
uiItems.push(



onChange={this.handleChangeHN.bind(this)}
/>


placeholder="Pick Dev Name..."
styles={colourStyles}
options={options2}
onChange={this.handleChangeDN}
/>





)
return uiItems;
}

deleteRow(currentID) {
// const changedID = this.state.id.filter(i => i.id !== currentID)
// this.setState({changedID});
// console.log(Clicked: ${currentID});
// this.setState({ count: this.state.count - 1 })
console.log("delete");
};

Top comments (1)

Collapse
 
dance2die profile image
Sung M. Kim

Hi Shivani.

Could you format the code snippet & add highlights according to the Editor Guide to increase the chance to get help?