一. 环境
next.js: “12.1.6”
react.js: “18.1.0”
三. 报错内容

三. 报错原因
3.1 第一种情况

p标签嵌套了p标签或者p标签嵌套了div标签,如下如:


将p的子标签改为span或者将父级p标签改为div也行。

一般来说,我们不会用p来嵌套div,也不能来嵌套。

需要注意的就是next.js中不允许p标签嵌套p标签。

3.1 第二种情况

首页有如下弹框:


当勾选确认且点击Confirm后,就会在本地存储一个状态,有这个状态的话就不再弹这个弹框,没有的话就需要弹出来。代码如下:

const [showHomeModel, setShowHomeModel] = useState(true)
useEffect(() => {if (localStorage.getItem('alreadyChecked')) {setShowHomeModel(false)} else {setShowHomeModel(true)}
}, [])
// 弹框组件
<HomeModel visibleInfo={showHomeModel} changeVisible={setShowHomeModel} />

结果每次进入页面都会报上面那个错误!

仔细分析了下,首次进入页面时,是没有状态的,所有useEffect里面走的是else条件,会把showHomeModel设置为true,而useState设置的showHomeModel初始值也为true,这样就引起了上面的报错。

所以代码改一下const [showHomeModel, setShowHomeModel] = useState(false)就不报那个错了。没有状态的时候进入页面也一定会拉起弹窗。

(完)

Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一相关推荐

  1. Hydration failed because the initial UI does not match what was rendered on the server

    react18在nextjs中包错,解决方法: 1.方法1 react 18降到17 2. 方法2 如下图 参考: https://github.com/vercel/next.js/discussi ...

  2. ERROR 220624 --- [ntainer#2-2-C-1] o.s.k.l.KafkaMessageListenerContainer : Failed to set initial

    完整报错: org.apache.kafka.common.errors.TimeoutException: Timeout of 60000ms expired before the positio ...

  3. 打开eclipse出现Failed to load the JNI shared library “D:\java\jdk\bin\...\jre\bin\server\jvm.dll”如何解决?

    eclipse打开的时候出现Failed to load the JNI shared library "D:\java\jdk\bin-\jre\bin\server\jvm.dll&qu ...

  4. The job failed. Unable to determine if the owner (SINOOCEANLAND\v-baidd) of job sendmail has server

    执行作业时报错: The job failed.  Unable to determine if the owner (SINOOCEANLAND\v-baidd) of job sendmail h ...

  5. 导入AAR报错 Failed to transform file 'xxx.aar' to match attributes {artifactType=jar}

    Failed to transform file 'xxx.aar' to match attributes {artifactType=jar} Failed to transform file ' ...

  6. 报错:FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask原因查找

    项目场景: 使用hive分析.处理数据时 问题描述 执行hive语句后,报错:FAILED: Execution Error, return code 2 from org.apache.hadoop ...

  7. android 项目Failed to transform file ‘xxxxx.jar‘ to match attributes 解决方法

    最近接入第三方依赖时报错 Execution failed for task ':vivoads:compileDebugKotlin'. > Could not resolve all fil ...

  8. Integrity check failed for “antd“ (computed integrity doesn‘t match our records

    1.清理缓存 yarn cache clean2.安装依赖 命令参考 https://classic.yarnpkg.com/en/docs/cli/install/yarn install --no ...

  9. 原理实践 SSR中redux的使用

    原理实践 SSR中redux的使用 文章目录 原理实践 SSR中redux的使用 @reduxjs/toolkit 主要API 快速上手 创建 使用 redux在SSR中的使用 安装 yarn add ...

最新文章

  1. 获得PMP证书的这一年
  2. 联发科有没有高端处理器_联发科陷入“危机”,高端处理器无人使用,只能依靠OPPO?...
  3. 当程序崩溃的时候怎么办
  4. 3D图形学的线性代数的通俗解释。
  5. 三种方式实现日志记录
  6. Centos7编译安装nginx并设置反向代理
  7. GenericUDTF使用流程记载(转载+自己整理)
  8. 如何使用代码给product创建distribution chain
  9. Node.js -- 目录
  10. 无密码退出、卸载趋势防毒墙网络版
  11. 汉仪字体安装后PPT找不到_字体不知道去哪下载?我教您
  12. 树莓派Zero的千兆测速
  13. python求职意向怎么写_怎样写好求职简历?
  14. 常见的负载均衡器(一)
  15. 2023MyBatis全新面试题【30题】
  16. STM32F429第二十八篇之ADC
  17. 【风变编程】第五课笔记
  18. python取元素_python 如何提取对象内的元素
  19. 从0开始写前端UI框架:概述
  20. MySQL5.7.18安装卡在了starting server

热门文章

  1. python 对excel的函数操作(2)
  2. win8宽带连接服务器未响应,关于Win8系统连接宽带错误的解决方法介绍
  3. echarts修改标题字体大小、颜色、位置、内容
  4. vxWorks启动时间
  5. linux运行blast,linux blast
  6. 设置用户ID位是什么意思
  7. linux宿主机ssh访问windows10虚拟机
  8. 如何智慧的提问(个人笔记)
  9. Python破解pdf打开密码
  10. 基于内容的图像检索技术