Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigProvider组件在nextjs13.4 app目录项目中能像antd-design一样,提供类似AntdRegistry.tsx来支持ssr配置多语言嘛 #6423

Closed
loakliu opened this issue Nov 2, 2023 · 7 comments

Comments

@loakliu
Copy link

loakliu commented Nov 2, 2023

Version of antd-mobile

5.33

Operating system and its version

Others

Browser and its version

No response

Sandbox to reproduce

No response

What happened?

image

我在next.js 中像antd-design一样配置ConfigProvider组件,但却提示必须要添加‘use client’
能否像antd-design一样,支持让ConfigProvider组件可以不需要添加‘use client’
https://ant-design.antgroup.com/docs/react/use-with-next-cn

下面是报错信息:
image

Relevant log output

No response

@loakliu loakliu added the bug label Nov 2, 2023
@zombieJ
Copy link
Member

zombieJ commented Nov 2, 2023

感觉可以加一个

@loakliu
Copy link
Author

loakliu commented Nov 3, 2023

感觉可以加一个

现有方案上,有啥好思路可以不升级解决嘛~
我目前能想到的就是,把configProvider降低dom树的层级,hook一层,在使用的页面/组件,添加‘use client’,再provider,有其他的思路可以提供下嘛

@loakliu
Copy link
Author

loakliu commented Nov 22, 2023

这个是我的解决方案,在next项目中,创建configProvider.tsx,然后将组件挂载到layout.tsx中,参考的是next官网给的例子:https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers
这个我先关闭了。
`
'use client';
//type
import { Locale } from 'antd-mobile/es/locales/base';

//ts
import { ConfigProvider } from 'antd-mobile';
import { createContext } from 'react';
import en from 'antd-mobile/es/locales/en-US';
import cn from 'antd-mobile/es/locales/zh-CN';

interface AntdLngConfigProps {
[key: string]: Locale;
}
interface MobileConfigProviderType {
children: React.ReactNode;
lng: string;
}
const AntdMobileLngConfig: AntdLngConfigProps = {
en,
cn,
};

export const mobileConfigContext = createContext();
export default function MobileConfigProvider({ children, lng }: MobileConfigProviderType) {
return (
<mobileConfigContext.Provider value={lng}>
{children}
</mobileConfigContext.Provider>
);
}
`

@loakliu loakliu closed this as completed Nov 22, 2023
@bingqichen
Copy link

这个是我的解决方案,在next项目中,创建configProvider.tsx,然后将组件挂载到layout.tsx中,参考的是next官网给的例子:https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers 这个我先关闭了。 ` 'use client'; //type import { Locale } from 'antd-mobile/es/locales/base';

//ts import { ConfigProvider } from 'antd-mobile'; import { createContext } from 'react'; import en from 'antd-mobile/es/locales/en-US'; import cn from 'antd-mobile/es/locales/zh-CN';

interface AntdLngConfigProps { [key: string]: Locale; } interface MobileConfigProviderType { children: React.ReactNode; lng: string; } const AntdMobileLngConfig: AntdLngConfigProps = { en, cn, };

export const mobileConfigContext = createContext(); export default function MobileConfigProvider({ children, lng }: MobileConfigProviderType) { return ( <mobileConfigContext.Provider value={lng}> {children} </mobileConfigContext.Provider> ); } `

你好,问一下你这个是完整的吗,我反复试了一下没有效果,想请教一下有没有最小实现的代码参考一下

@loakliu
Copy link
Author

loakliu commented Feb 19, 2024

这个是我的解决方案,在next项目中,创建configProvider.tsx,然后将组件挂载到layout.tsx中,参考的是next官网给的例子:https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers 这个我先关闭了。 'use client'; //type import { Locale } from 'antd-mobile/es/locales/base'; //ts import { ConfigProvider } from 'antd-mobile'; import { createContext } from 'react'; import en from 'antd-mobile/es/locales/en-US'; import cn from 'antd-mobile/es/locales/zh-CN'; interface AntdLngConfigProps { [key: string]: Locale; } interface MobileConfigProviderType { children: React.ReactNode; lng: string; } const AntdMobileLngConfig: AntdLngConfigProps = { en, cn, }; export const mobileConfigContext = createContext(); export default function MobileConfigProvider({ children, lng }: MobileConfigProviderType) { return ( <mobileConfigContext.Provider value={lng}> {children} </mobileConfigContext.Provider> ); }

你好,问一下你这个是完整的吗,我反复试了一下没有效果,想请教一下有没有最小实现的代码参考一下

是完整的,都已经运用在生产环境了,我的代码是公司内部,不方便粘贴一个demo出来,整个就是一个configProvider.tsx,具体是跟antd的一模一样的,使用你可以参考这里https://ant.design/docs/react/use-with-next-cn 里面有一个App router对应的

@loakliu
Copy link
Author

loakliu commented Feb 19, 2024

这个是我的解决方案,在next项目中,创建configProvider.tsx,然后将组件挂载到layout.tsx中,参考的是next官网给的例子:https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers 这个我先关闭了。 'use client'; //type import { Locale } from 'antd-mobile/es/locales/base'; //ts import { ConfigProvider } from 'antd-mobile'; import { createContext } from 'react'; import en from 'antd-mobile/es/locales/en-US'; import cn from 'antd-mobile/es/locales/zh-CN'; interface AntdLngConfigProps { [key: string]: Locale; } interface MobileConfigProviderType { children: React.ReactNode; lng: string; } const AntdMobileLngConfig: AntdLngConfigProps = { en, cn, }; export const mobileConfigContext = createContext(); export default function MobileConfigProvider({ children, lng }: MobileConfigProviderType) { return ( <mobileConfigContext.Provider value={lng}> {children} </mobileConfigContext.Provider> ); }

你好,问一下你这个是完整的吗,我反复试了一下没有效果,想请教一下有没有最小实现的代码参考一下

这个是我的解决方案,在next项目中,创建configProvider.tsx,然后将组件挂载到layout.tsx中,参考的是next官网给的例子:https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers 这个我先关闭了。 'use client'; //type import { Locale } from 'antd-mobile/es/locales/base'; //ts import { ConfigProvider } from 'antd-mobile'; import { createContext } from 'react'; import en from 'antd-mobile/es/locales/en-US'; import cn from 'antd-mobile/es/locales/zh-CN'; interface AntdLngConfigProps { [key: string]: Locale; } interface MobileConfigProviderType { children: React.ReactNode; lng: string; } const AntdMobileLngConfig: AntdLngConfigProps = { en, cn, }; export const mobileConfigContext = createContext(); export default function MobileConfigProvider({ children, lng }: MobileConfigProviderType) { return ( <mobileConfigContext.Provider value={lng}> {children} </mobileConfigContext.Provider> ); }

你好,问一下你这个是完整的吗,我反复试了一下没有效果,想请教一下有没有最小实现的代码参考一下

方便的话,你可以把你的demo贴出来下,我可以抽空帮你看看

@bingqichen
Copy link

@loakliu 可以了,感谢兄弟相助!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants