[英]'Functions are not valid as a React child' when trying to dynamically include Components for SSR bundle
From my express route I'm trying to pass a component to use in a render function, that handles SSR. 从我的快速路线中,我试图传递要在处理SSR的渲染函数中使用的组件。
Express Route: 快速路线:
import SettingsConnected from '../../../client/components/settings/settings-connected';
function accountTab(req, res, next) {
sendToRenderApp(req, res, { profileInfo }, url, SettingsConnected);
}
Render helper: 渲染助手:
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));
Error: 错误:
" Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it. " “ 警告:函数作为React子元素无效。如果您返回Component而不是从render中返回,则可能会发生这种情况。或者您可能打算调用此函数而不是返回它。 ”
Things I've already had a look at include this answer below, but I'm not sure how to wrap such a function inside (what I presume) the Provider component? 我已经看过的东西包括下面的答案,但是我不确定如何在Provider组件内部包装这样的函数(我认为是这样)?
Functions are not valid as a React child. 函数作为React子代无效。 This may happen if you return a Component instead of from render
如果您返回Component而不是从render返回,则可能会发生这种情况
ANSWERING OWN QUESTION: Turned out to be a problem with the client's hydrate. 回答自己的问题:原来是客户的水合物有问题。 This piece of code above was fine all along - :facepalm:
上面的这段代码一直很好-:facepalm:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.