В
Size: a a a
CM
В
let items = [
{id: 1, text: 'Text1'},
{id: 2, text: 'Text2'}
];
class List extends React.Component {
render() {
return (
<ul>
{
items.map((item, i) => (
<Item key={i} { ...item } />
))
}
</ul>
);
}
}
class Item extends React.Component {
clickHandler = (e) => {
let { id } = this.props;
console.log(id, e);
};
render() {
let { text } = this.props;
return (
<li onClick={this.clickHandler}>{text}</li>
);
}
}
S
let items = [
{id: 1, text: 'Text1'},
{id: 2, text: 'Text2'}
];
class List extends React.Component {
render() {
return (
<ul>
{
items.map((item, i) => (
<Item key={i} { ...item } />
))
}
</ul>
);
}
}
class Item extends React.Component {
clickHandler = (e) => {
let { id } = this.props;
console.log(id, e);
};
render() {
let { text } = this.props;
return (
<li onClick={this.clickHandler}>{text}</li>
);
}
}
CM
F