Я делаю простое приложение для адресной книги с использованием response-bootstrap. Я успешно реализовал методы для добавления нового контакта или удаления существующего контакта, но у меня возникают проблемы с обновлением существующих контактов. На данный момент, когда я нажимаю кнопку «Изменить», чтобы обновить контакт, добавляется новый контакт с «обновленной» информацией вместо замены выбранного контакта. Мои контакты хранятся в массиве объектов под названием «люди»
Вот мой полный исходный код: https://github.com/DeonChoi/address-book
constructor(props){
super(props);
this.state = {
show: false,
people: [],
firstName: '',
lastName: '',
address: '',
city: '',
country: '',
postalCode: null,
phone: null,
email: '',
age: null
};
this.editPerson = this.editPerson.bind(this);
}
editPerson = (index) => {
this.setState(state => {
const people = state.people.map((person, personIndex) => {
if (personIndex === index) {
person.newFirstName = this.state.firstName;
person.newLastName = this.state.lastName;
person.newAddress = this.state.address;
person.newCity = this.state.city;
person.newCountry = this.state.country;
person.newPostalCode = this.state.postalCode;
person.newPhone = this.state.phone;
person.newEmail = this.state.email;
person.newAge = this.state.age;
return person;
} else {
return person;
}
});
return {
people,
};
});
}