This error happens when using the isMobile
property from the react-device-detect
library for conditional rendering.
To get to this error, I created a new next app using npx create-next-app
, then installed the react-device-detect
package with npm. Then I just replaced the index.js with this :
import {
BrowserView,
MobileView
} from 'react-device-detect'
export default function Home() {
return <div>
<BrowserView>Hello</BrowserView>
<MobileView>World</MobileView>
</div>
}
When I start the development server and open the page on the desktop, I see Hello and no error. But when I go on Safari on my phone, I see World but I can see in the development tools that I also get this warning message :
Warning: Text content did not match. Server: "Hello" Client: "World"
div
MobileView
div
Home
MyApp
PureComponent
ReactDevOverlay
_classCallCheck
AppContainer
Root
I've read some articles about hydration and seen that I can add the suppressHydrationWarning property to suppress this warning, but is this what I should do here, or am I not understanding something?