TypeError: (0 , _ahooks.createUpdateEffect) is not a function

本文讲述了在使用Next.js时遇到的Antd-Mobile库与服务器端渲染不兼容的问题,通过动态导入非SSR方式解决了该问题,但指出这种方法的不便。作者寻求更简便的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

版本  "next": "14.0.4",  "antd-mobile": "^5.34.0",

next中使用antd-mobile可困难了.主要是因为antd-mobile不支持ssr

1.下载antd-mobile包,在next.config.js中加入

   transpilePackages: [
     'antd-mobile',
  ],

2.在页面中引入antd-mobile组件

然后就报错了

import Head from "next/head";
import Image from "next/image";
import { Inter } from "next/font/google";
import styles from "@/styles/Home.module.css";
import { Button } from "antd-mobile";
const inter = Inter({ subsets: ["latin"] });

export default function Home() {
  return (
    <>
     <Button></Button>
    </>
  );
}

3.使用next的dynamic

import dynamic from "next/dynamic";
const Active = dynamic(() => import("../components/home/active"), {
  ssr: false,
});

把引入antdmobile 的那个组件用非ssr的方式引入

然后能正常使用,但是好麻烦.只要用到antdmobile的组件都得用非ssr的方式引入.去找找更好的方法

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值