Reputation: 31
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
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
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