4 ms·
As someone who loves React, the hardest thing about it for me is debugging. I'll get some error about how renderComponent doesn't accept null values or whatever
by brhsiao 10y ago
As someone who loves React, the hardest thing about it for me is debugging. I'll get some error about how renderComponent doesn't accept null values or whatever, and when even the outermost error is so cryptic, the stack trace is even less helpful. Is there a conventional solution to this I'm not aware of?
- dwaltrip 10y agoWhen the stack trace is inscrutable, I find binary search debugging to be helpful. Comment out half of the functionality, see if the error is still there. Narrow the search to the half that is causing the problem, rinse, and repeat until the offending line of code is found. However, if the error occurs inconsistently, this approach can be much harder to use.
- darkmarmot 10y agoAs someone who uses a different component-based js framework, can you not just put a breakpoint in the chrome dev tools on the renderComponent method for that component?
- larsnystrom 10y agorenderComponent is not part of any of your components. I think the React equivalent of what you mean is the render method of a component. The problem I think the OP is talking about is when there is an error thrown somewhere in the react library code (e.g. in renderComponent) and the stack trace doesn't even touch any of your code. That makes it really hard to find the fault behind the error. This is a lot more common with libraries like RxJS, but I've seen it with React as well. The only way I know of to deal with these situations is to put console.log calls everywhere in my code until I've narrowed down the source of the bug.
- darkmarmot 10y agogotcha, thanks!