8

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)?

Obiwahn
  • 2,677
  • 2
  • 26
  • 36

2 Answers2

2

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?

mossherder
  • 135
  • 7
  • 1
    This answer recommends to use Context, which does not seem to help here, right? Also there is a kind of hackish answer that suggests using componentWillMount which does not look like an ideal solution to mee? – Obiwahn Apr 15 '19 at 08:05
1

Refer this site -: IT gives you the complete guide for that or if you face any issue feel free to ask https://developers.google.com/web/tools/chrome-devtools/console/

Janmesh Nayak
  • 47
  • 2
  • 3
  • 12
  • Open the Console as a dedicated panel or as a drawer next to any other panel. Stack redundant messages, or display them on their own lines. Clear or persist output between pages, or save it to a file. Filter output by severity level, by hiding network messages, or by regular expression patterns. – Janmesh Nayak Apr 15 '19 at 07:07