reactjs - How do I debug when React.js produces no output?
问题描述
I have worked with React.js on and off for several years. When I make certain kinds of mistakes in the jsx code, React.js silently fails. Here's what happens:
- Compilation (with webpack) appears to succeed and produces no error messages or warnings.
- But when I open my index.html file, all React components are missing from the page. (The nav bar, which I have coded directly into my index.html file, is still present and is styled correctly. Below that, where my React content is supposed to be, the page is blank.)
- The browser console doesn't show any error messages.
- For some mistakes, when I inspect different versions of the page source using my browser, I see that the
<div data-reactroot>
element was present before my breaking change, but is now absent. For other mistakes,<div data-reactroot>
is present, but its contents are empty or commented out.
There is no error message to help pinpoint the source of the problem, and in my experience this same behavior can be caused by many different kinds of mistakes. So my question is, how should one debug these silent failures from React?
I'm looking for a general debugging approach, analogous to these tips for debugging CSS. Good answers might include a list of mistakes to check for, useful debugging tools, or other ways to narrow down the cause of the problem.
解决方案
推荐阅读
- scala - 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/kafka/common/errors/TimeoutException
- python - 如何迭代地向 Pandas Dataframe 中的多行添加随机值?
- java - mkdirs() 已成功执行,但该文件夹在 Honor 9i 中不可见
- php - 如何获取文件内容作为文本区域值?
- vscode-remote - 当我通过 SSH 连接时,我可以停止 VSCode 远程服务器重新安装吗?
- c - 单独使用指针和 malloc,如何定义 2D int 数组?我的似乎不起作用。(段错误)
- android - 服务器更改json文件时如何更改背景颜色
- python - 如何在 Django 中正确迁移自定义 UserModel
- apache-spark - 火花错误:java.lang.UnsatisfiedLinkError:/tmp/snappy-1.0.4.1-libsnappyjava
- c++ - std::promise 是否在内部使用 std::condition_variable 来通知关联的 std::future?