简体   繁体   English

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

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

I am using ReactJS.net to render react server side 我正在使用ReactJS.net来呈现反应服务器端

Below is the code in my cshtml file 下面是我的cshtml文件中的代码

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

Here i need to pass services to the child component. 在这里,我需要将服务传递给子组件。 I have also declared the object in my entry point file 我还在我的入口点文件中声明了该对象

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

global.service = service ;

Is there a way to access that object 有没有办法访问该对象

Should it be = instead of : ? 应该是=而不是

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

The written above means that in your RootComponent you will be able to access services in it's props . 上面写的意味着在你的RootComponent你将能够访问它的props services
So, it will be something like 所以,它会是这样的

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

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

or 要么

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

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

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