素肌にサスペンダー

個人的な備忘と日記

【Next.js】Hydration failed because the initial UI does not match what was rendered on the server.が出たときの対応

Next.jsでUIを実装していると、以下のエラーが出た。

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

マークアップがおかしい時に出るみたい。

自分の場合は、aタグの中にaタグを入れてしまってた。

リンク要素が入れ子になっている場合、どちらかをbutton要素にしてonclickで処理することで回避した。