LoginSignup
4

More than 3 years have passed since last update.

React子コンポーネントから親の引数付きメソッドを実行する

Last updated at Posted at 2019-05-16
親コンポーネント.js
  // 実行したいメソッド
  myMethod(i) {
    console.log(i);
  }

  render() {
    return (
      <View>
        <Child callMethod={(i) => this.myMethod(i) } />
      </View>
    );
  }
子コンポーネント.js
    return (
      <TouchableHighlight onPress={() => {this.props.callMethod(1)}}>
        <View>
          <Text>...</Text>
        </View>
      </TouchableHighlight>
    );
1

以上

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4