Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging React propType warnings

I have propType expressions that sometimes are emitting warnings.

When that happens, I would like to inspect the object causing the warning since the warning message in the console is in same cases not helpful enough.

I tried to debugging through the spec code of react to find the right spot for the breakpoint, however i would expect there is an easier way to get more diagnostic information about the warning.

like image 297
JE42 Avatar asked Sep 07 '16 08:09

JE42


People also ask

Is React Proptype deprecated?

As of React v15. 5 PropTypes are deprecated in the React package and have been given a package of their own. Change is an inevitable part of life.

Why PropTypes is used in React?

PropTypes are simply a mechanism that ensures that the passed value is of the correct datatype. This makes sure that we don't receive an error at the very end of our app by the console which might not be easy to deal with.


1 Answers

Want the ugly solution? Because that's all I have.

Stick this in your main application file.

const error = console.error;
console.error = (...args) => {
    debugger;
    error.apply(null, args);
}

And use the debugger to walk up the callchain till you find checkReactTypeSpec and look at its arguments.

like image 175
ivarni Avatar answered Sep 22 '22 12:09

ivarni