0

Sorry the headline might be confusing, I didn't know how to do the right wording. So I tired the example from this answer https://stackoverflow.com/a/50466217/12848667 and it works for me. I can call window.helloComponent.alertMessage() in the console and get the output.

import React from 'react';
import './App.css';

class App extends React.Component{
  constructor(){
    super();
    window.helloComponent = this;
  }

  alertMessage(){
    console.log("Called from outside");
  }

  render(){

    return (
      false
    )
  }
}

export default App;

Now I want to use that functionality in my App but I use hooks, I don't have a constructor and I don't have this.

How can I add this solution to a more modern hooks based/functional App without converting the whole App component to class based?

user6329530
  • 596
  • 1
  • 7
  • 21

0 Answers0