React js onClick can't pass value to method

后端 未结 30 1702
北荒
北荒 2020-11-22 07:05

I want to read the onClick event value properties. But when I click on it, I see something like this on the console:

SyntheticMouseEvent {dispatchConfig: Ob         


        
30条回答
  •  旧巷少年郎
    2020-11-22 07:25

    You can simply do it if you are using ES6.

    export default class Container extends Component {
      state = {
        data: [
            // ...
        ]
      }
    
      handleItemChange = (e, data) => {
          // here the data is available 
          // ....
      }
      render () {
         return (
            
    { this.state.data.map((item, index) => (
    this.handItemChange(event, item)} value={item.value}/>
    )) }
    ); } }

提交回复
热议问题