在ReasonReact中继承Nextjs App组件(pages / _app.js)

问题描述 投票:2回答:1

我正在尝试使用ReasonReact在我的Nextjs应用程序中实现React Context API,但是被bucklescript编译器推断出模块名称的方式。

为了使上下文可用于整个树,我需要从Nextjs App组件继承。问题是Next按惯例查看pages/_app.js的App组件继承,但是当我使用_app.re作为文件名时,bsb不会生成名为“App”的Reason模块。

事实上,bsb打印以下消息并忽略该文件:

IGNORED: file _app.re under pages is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter

有没有办法告诉Nextjs寻找其他地方的App组件?或者也许是一种方法来调整bsb这个文件?

最后一个似乎是一个很长的镜头,但我不想深入了解javascript,除非我真的需要。

reactjs next.js react-context reason-react bsb
1个回答
3
投票

一种可能的解决方案是添加一个具有适当名称的js文件,该文件从已编译模块重新导出,其名称为BuckleScript支持的名称:

// _app.js
export { default } from './next_app.bs.js';

我必须这样做以使某些功能与Gatsby一起使用。见this example

© www.soinside.com 2019 - 2024. All rights reserved.