How to call method from different class. I was looking for React getting started, but all examples are about rendering component. i just want to set some variables.
I have tried this. How to call testMethod from class App?
class App extends React.Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
}
componentDidMount() {
this.myRef.current.testMethod();
{
}
render(){
return(
<TestClass ref={this.myRef} />
)
}
export default App;
Second class
class TestClass extends React.Component
{
testMethod = () => {
console.log("testMethod")
}
render(){
return(
<h1>Hello</h1>
)
}
}
but getting error
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.