Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 使用Apollo堆栈SSR处理UI事件_User Interface_Reactjs_Apollo - Fatal编程技术网

User interface 使用Apollo堆栈SSR处理UI事件

User interface 使用Apollo堆栈SSR处理UI事件,user-interface,reactjs,apollo,User Interface,Reactjs,Apollo,我目前正在将一些React客户端渲染迁移到服务器端渲染,但我不知道如何调用函数,一旦在视图中触发元素,就不会发生任何事情 我在我的组件中定义了一些函数,但一旦单击触发器,就好像在渲染后单击被删除一样 match({ history, routes, location: req.url }, (err, redirectLocation, renderProps) => { if (err) { return res.status(500).send(err.message);

我目前正在将一些React客户端渲染迁移到服务器端渲染,但我不知道如何调用函数,一旦在视图中触发元素,就不会发生任何事情

我在我的组件中定义了一些函数,但一旦单击触发器,就好像在渲染后单击被删除一样

match({ history, routes, location: req.url }, (err, redirectLocation, renderProps) => {
  if (err) {
    return res.status(500).send(err.message);
  }

  if (redirectLocation) {
    return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
  }

  if (!renderProps) {
    return res.status(404).send('Not found');
  }

  const app = (
      <ApolloProvider client={apolloClient} >
        <RouterContext {...renderProps}/>
      </ApolloProvider>
  );

  renderToStringWithData(app).then((content) => {
    const initialState = {[apolloClient.reduxRootKey]: apolloClient.getInitialState() };
    const html = <Html content={content} state={initialState} />;

    res.status(200);
    res.send(`<!doctype html>\n${ReactDOMServer.renderToStaticMarkup(html)}`);
    res.end();
});
match({history,routes,location:req.url},(err,redirectLocation,renderProps)=>{
如果(错误){
返回res.status(500.send)(错误消息);
}
如果(重定向位置){
返回res.redirect(302,redirectLocation.pathname+redirectLocation.search);
}
如果(!renderProps){
返回res.status(404.send('notfound');
}
常量应用=(
);
renderToStringWithData(应用程序)。然后((内容)=>{
const initialState={[apolloClient.reduxRootKey]:apolloClient.getInitialState()};
常量html=;
物质状态(200);
res.send(`\n${ReactDOMServer.renderToStaticMarkup(html)}`);
res.end();
});

你能分享你的代码吗?你是如何在服务器端呈现应用程序的?我用更多的代码更新了我的问题你所说的“就像呈现后点击被删除了”是什么意思?由于这是在服务器上渲染的,我没有一次渲染onclick prop。您以前使用React而不使用Apollo进行过服务器端渲染吗?有一些关于必须再次在客户端渲染的细节,我认为这个问题与Apollo无关,但可能只是React问题。