【发布时间】:2021-05-26 12:35:53
【问题描述】:
我在 react 中有一个配置组件,我需要将实例导出到另一个外部组件,在这种情况下是: const appInstance
export const setupApp = () => {
if (isAppAvailable) {
try {
{...}
const appConfiguration = new AppConfiguration(KEY);
AppConfig.configure(appConfiguration);
// I need to export this const
const appInstance = AppConfig.start(startInstance);
} catch (e) {
console.error(e);
}
}
};
在其他组件中,我需要使用这个实例,如下所示:
// get app instance from another page
appInstance.get(myTest)
.then((value) => {
if (...) {
something
} else {
something;
}
});
我该怎么做?
【问题讨论】:
-
你可以提供的是顶级上下文提供者
-
你能更好地解释一下我该怎么做吗?
标签: javascript reactjs constants