1
我有一個像這樣構建的React組件,它從父組件中接收回調函數。當火的onClick,它調用從項目的值回調映射過來:將值從父組件傳遞到回調函數而不進行綁定
class Child extends Component {
static propTypes = {
...
}
render =() => {
return (
<div>
{this.props.data.map((el, idx) => {
return <section onClick={() = this.props.cb(el.val)}></section>
}
)}
</div>
);
}
}
什麼我不知道是我怎麼能做到通過從map
回調的值,而無需使用此語法() => this.props.cb(item.val)
或將值綁定到回調。我不能將回調傳遞給onClick
,因爲它會立即觸發值。
當前的語法有效,但打破了我在我的linter中設置的規則。
看https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md#lists-of-items – Hamms