Skip to content

Commit 0c59f67

Browse files
Simplify ReactRenderer API when referencing default modules
1 parent 7e1955c commit 0c59f67

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

Microsoft.AspNet.NodeServices.React/Content/Node/react-rendering.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
renderToString: function(callback, options) {
2828
var resolvedPath = path.resolve(process.cwd(), options.moduleName);
2929
var requestedModule = require(resolvedPath);
30-
var component = requestedModule[options.exportName];
30+
var component = options.exportName ? requestedModule[options.exportName] : requestedModule;
3131
if (!component) {
3232
throw new Error('The module "' + resolvedPath + '" has no export named "' + options.exportName + '"');
3333
}

Microsoft.AspNet.NodeServices.React/ReactRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ static ReactRenderer() {
1212
nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit
1313
}
1414

15+
public static Task<string> RenderToString(INodeServices nodeServices, string moduleName, string baseUrl) {
16+
return RenderToString(nodeServices, moduleName, /* exportName */ null, baseUrl);
17+
}
18+
1519
public static async Task<string> RenderToString(INodeServices nodeServices, string moduleName, string exportName, string baseUrl) {
1620
return await nodeServices.InvokeExport(nodeScript.FileName, "renderToString", new {
1721
moduleName,

samples/react/ReactGrid/Controllers/HomeController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public async Task<IActionResult> Index(int pageIndex)
1717
{
1818
ViewData["ReactOutput"] = await ReactRenderer.RenderToString(this.nodeServices,
1919
moduleName: "ReactApp/components/ReactApp.jsx",
20-
exportName: "ReactApp",
2120
baseUrl: Request.Path
2221
);
2322
return View();

samples/react/ReactGrid/ReactApp/boot-client.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import createBrowserHistory from 'history/lib/createBrowserHistory';
4-
import { ReactApp } from './components/ReactApp.jsx';
4+
import ReactApp from './components/ReactApp.jsx';
55

66
// In the browser, we render into a DOM node and hook up to the browser's history APIs
77
var history = createBrowserHistory();

samples/react/ReactGrid/ReactApp/components/ReactApp.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Router, Route } from 'react-router';
33
import { PeopleGrid } from './PeopleGrid.jsx';
44

5-
export class ReactApp extends React.Component {
5+
export default class ReactApp extends React.Component {
66
render() {
77
return (
88
<Router history={this.props.history}>

0 commit comments

Comments
 (0)