Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add debug functions that I can call from Chrome Debugger Console to a Create React App?

I created an app with Create React App.

How can I add global debug functions (e.g. resetDatabase()) that I can call from Chromes Debug Console (or some other way)?

like image 375
Obiwahn Avatar asked Apr 01 '19 12:04

Obiwahn


1 Answers

You can attach the function to the global window object, or some namespaced object.

Then in the console you can run it with:

window.resetDatabase();

Here’s a link to a relevant post about accessing the global context through the componentWillMount callback.

How to declare a global variable in React?

like image 187
mossherder Avatar answered Nov 02 '22 12:11

mossherder