Skip to content

Added some changes#9

Open
olegobiukh wants to merge 13 commits intomasterfrom
dev
Open

Added some changes#9
olegobiukh wants to merge 13 commits intomasterfrom
dev

Conversation

@olegobiukh
Copy link
Owner

@olegobiukh olegobiukh commented Mar 25, 2019

Copy link

@vadim-ilchenko vadim-ilchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Принимаю. Оставил комментарии по возможным улучшениям

<input
type="checkbox"
checked={checkedItems.length === filteredItems.length}
onChange={onMainCheck.bind(this)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какой-то здесь странный bind. Оно без него не работает?

<td>
<input
type="checkbox"
checked={checkedItems.includes(item.id)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут можно в item записывать item.checked

<input
type="checkbox"
checked={checkedItems.includes(item.id)}
onChange={onHandleCheck.bind(this)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь тоже не понятно, что за bind

&#8592;
</button>
)}
{pages.map(item => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не совсем оптимальное решение через map. Для того, чтобы показать 3 страницы, ты проходишь по массиву из всех страниц. Думаю можно оптимизировать

if (checkedItems.includes(id)) {
newArr = checkedItems.filter(item => item !== id);
} else {
newArr = [...checkedItems, id];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 прохода по массиву за 3 строки.
id можно передавать при вызове функции, это избавит от event.target.value
Вместо создания массива checkedItems можно создать поле checked у каждого айтема и работать с ним. Все равно ты в componentDidMount записываешь в state список телефонов. Можно уже с ним работать, как хочешь

checkedItems: newArr,
isMainChecked: event.target.checked
});
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если использовать item.checked, то можно здесь обойтись одним mapом:

this.setState(items: items.map(item => ({...item, checked: !event.target.checked}))})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants