I am developing my first application and still learning the flow. Therefore, suppose I have a component:
The parent that contains the HelloWorld () method, as in the following example:
import React, { Component } from 'react';
class Parent extends Component {
Helloworld() {
console.log('Hello world');
}
render () {
return (
<View>{this.props.children}</View>
)
}
}
module.exports = Parent;
and then I want to import this into another component and use its method, then how to do it? Ill write another short example of how I implement it.
import React, { Component } from 'react';
import { Parent } from 'path to parent';
const Parent = require('path to parent');
class Home extends Component {
Helloworld() {
console.log('Hello world');
}
render () {
return (
<Parent>
// this is what i need
<Button onClick={parent.Helloword()}>Some Button</Button>
</Parent>
)
}
}
module.exports = Home;
Thank you for your help.
source
share