1

Пишу простой Todo List на React

const list = this.props.item.map((item, index) => {
        return <li key={index}
                   style={{
                       backgroundColor: item.noted ? 'white' : 'red'
                   }}
                   onClick={this.selectCategory.bind(this, index)}
                >
            {item.value}
            <button>edit</button>
            <input
                type="submit"
                value="Delete"
                onClick={this.deleteItem.bind(this, index)}

            />
            <button>add</button>
        </li>;
    });

Есть 2 onClick если нажать первый то сработает только он, но если нажать на второй то сработают оба, хотя я хочу что б сработал только второй. Что делать?

1 ответ 1

2

stopPropagination в дочернем элементе:

<Parent
    onClick={
        (e) => {
            console.log('Parent');
        }
    }
>
    <Child
        onClick={(e) => {
            e.stopPropagation();
            console.log('Child');
        }}
    />
</Parent>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.