繁体   English   中英

在React服务器端呈现中将Javascript对象作为prop传递

[英]Pass Javascript object as prop in React server side rendering

我正在使用ReactJS.net来呈现反应服务器端

下面是我的cshtml文件中的代码

@Html.ReactRouter("RootComponent", new {services="service" }, containerId: "containerID")

在这里,我需要将服务传递给子组件。 我还在我的入口点文件中声明了该对象

import service from '../../src/components/service.jsx';

global.service = service ;

有没有办法访问该对象

应该是=而不是

@Html.ReactRouter("RootComponent", new {services = "service" }, containerId: "containerID")

上面写的意味着在你的RootComponent你将能够访问它的props services
所以,它会是这样的

class RootComponent extends React.PureComponent {
  // ...

  render () {
    const { services } = this.props;
    // ...
  }
}

要么

function RootComponent ({ services }) {
  // ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM