HighRoller
HighRoller

Reputation: 31

How can I call a function from Chrome console?

I have react component:

const App = ()=> {
function ASD() {
alert("ASD");}}

I want in Chrome console type ASD(); and get the alert.

Upvotes: 1

Views: 1996

Answers (2)

H S
H S

Reputation: 735

Presuming - your code might be looking like following, since the one OP has provided, is not a valid react-component -

const App = ()=> {
   function ASD() {
      alert("ASD");
   }
   window.ASD = ASD; // add this to read `ASD` from console by using "window.global"
   return null; // this was at-least missing for the App to be a valid functional component
}

OP wants to call ASD from console(developer-console in Chrome). That could be done by attaching the function to the window global variable - like done in the above code.

Upvotes: 1

Benjamin
Benjamin

Reputation: 3656

Just add it to the global window object.

function ASD() {
  alert('ASD');
}
window.ASD = ASD;

const App = () => {};

console

ASD(); // or
window.ASD();

Upvotes: 2

Related Questions