小编Aze*_*L87的帖子

接下来如何解决React水合错误

我不断收到错误消息“水合失败,因为初始 UI 与服务器上呈现的内容不匹配。”

我不知道是什么导致了错误,所以我希望其他人可能知道出了什么问题。我想我缩小了错误发生的范围,并在下面发布了我认为错误的代码。如果需要更多代码,请告诉我。

预先感谢您的所有帮助。

import React, { useEffect } from "react";
import styles from "../../styles/Home.module.css";
import Coin from "../Coin/Coin";

type CoinListProps = {
  coins: any;
};

const CoinList = ({ coins }: CoinListProps) => {
  useEffect(() => {
    console.log(coins);
  }, []);

  return (
    <div className={styles.coinList}>
      <table>
        <tr>
          <th>Coin</th>
          <th>Price</th>
          <th>24h</th>
        </tr>
        {coins.map((coin: any, index: any) => (
          <Coin key={index} coin={coin} />
        ))}
      </table>
    </div>
  );
};

export default CoinList;

Run Code Online (Sandbox Code Playgroud)

html javascript reactjs next.js

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

html ×1

javascript ×1

next.js ×1

reactjs ×1