尝试动态包含 SSR bundle的组件时'Functions are not valid as a React child'



从我的express路由中,我试图传递一个组件,用于处理SSR的呈现函数。

快速路线:

import SettingsConnected from '../../../client/components/settings/settings-connected';
function accountTab(req, res, next) {
sendToRenderApp(req, res, { profileInfo }, url, SettingsConnected);
}

渲染助手:

export const sendToRenderApp = (req, res, storeObj = {}, urlPath, componentFunc) => {
const store = configureStore(storeObj);
const dynamicComponent = componentFunc;
const component = (
<Provider store={store}>
<React.Fragment>
<dynamicComponent />
</React.Fragment>
</Provider>
);
const sheet = new ServerStyleSheet();
const app = renderToString(sheet.collectStyles(component));

错误:

">警告:函数作为React子函数无效。如果您返回组件而不是渲染,则可能会发生这种情况。或者您本想调用此函数而不是返回它。">

我已经看过的东西包括下面的答案,但我不确定如何将这样的函数封装在(我认为(Provider组件中?

函数作为React子函数无效。如果您返回组件而不是从渲染返回组件,则可能会发生这种情况

回答自己的问题:结果是客户的水合物有问题。上面的这段代码一直都很好-:facepalm:

相关内容

最新更新