React 16: Warning: Expected server HTML to contain a matching
in
due to State

前端 未结 4 1287
梦谈多话
梦谈多话 2021-01-07 22:43

I\'m getting the following error using SSR

Warning: Expected server HTML to contain a matching

in
.

The issue is on the c

4条回答
  •  时光取名叫无心
    2021-01-07 23:48

    The current accepted answer doesn’t play well with TypeScript. Here is what works for me.

    
    
      
        
        
        
      
      
        
        
    import React from "react"
    import { hydrate, render } from "react-dom"
    import BrowserRouter from "./routers/Browser"
    
    const root = document.getElementById("root")
    var renderMethod
    if (root && root.innerHTML !== "") {
      renderMethod = hydrate
    } else {
      renderMethod = render
    }
    renderMethod(, document.getElementById("root"))
    

提交回复
热议问题