React: Retrieve dynamic child key upon event

前端 未结 2 662
小鲜肉
小鲜肉 2021-02-05 05:39

I am aware that dynamic children of a component must have a unique key as the following (modified example from official docs):



        
2条回答
  •  面向向阳花
    2021-02-05 06:07

    Partially apply the function callback by using JavaScript's native bind. This is mentioned in React's "Communicate Between Components" doc:

    callbackFn: function(key) {
      // key is "result.id"
      this.props.callbackFn(key);
    },
    render: function() {
      var results = this.props.results;
      return (
        
    {results.map(function(result) { return ( ); }, this)}
    ); }

提交回复
热议问题