How to disable the “guard” feature in facebook react when working with pure javascript?

Question!

I would like to get the native javascript error and not their (react's) "guarded" error.

What is "guard": https://github.com/facebook/react/blob/9270d3d56ea3b196acc099409a38e6c07b191e46/src/vendor/stubs/ReactErrorUtils.js

https://github.com/facebook/react/search?q=guard&ref=cmdform

As you can see errors like Object [object Object] has no method 'map'. are hard to debug. (http://www.andrewgreig.com/637/)

For example I get this error:

undefined.__closeView: undefined is not a function react.js:7276
guarded react.js:7276
boundMethod react.js:4920

From this I cannot even know where to start to find what is undefined.

By : Totty.js


Answers

As you gave the guard implementation:

var ReactErrorUtils = {
  /**
   * Creates a guarded version of a function. This is supposed to make debugging
   * of event handlers easier. This implementation provides only basic error
   * logging and re-throws the error.
   *
   * @param {function} func Function to be executed
   * @param {string} name The name of the guard
   * @return {function}
   */
  guard: function(func, name) {
    if (__DEV__) {
      return function guarded() {
        try {
          return func.apply(this, arguments);
        } catch(ex) {
          console.error(name + ': ' + ex.message);
          throw ex;
        }
      };
    } else {
      return func;
    }
  }
};

https://github.com/facebook/react/blob/9270d3d56ea3b196acc099409a38e6c07b191e46/src/vendor/stubs/ReactErrorUtils.js

Maybe you can try to not be in __DEV__ mode, or open an issue to support an easy way to disable it.



This video can help you solving your question :)
By: admin