Skip to content

Commit e12020b

Browse files
committed
Various documentation tweaks
1 parent 79801ba commit e12020b

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

site/jekyll/_posts/2016-10-09-3.0.0-release.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ I'm happy to announce the release of ReactJS.NET 3.0! The major change in this r
1616
Other tweaks:
1717

1818
* [#323](https://github.com/reactjs/React.NET/issues/323) - Upgraded to React 15.3.2
19+
* [#331](https://github.com/reactjs/React.NET/issues/331) - Added option to totally disable server-side rendering. This is useful when debugging your React components, as it's easier to debug client-side
1920
* [#316](https://github.com/reactjs/React.NET/issues/316) - Added option to use production version of React, and enabled it by default. You can call `SetUseDebugReact(true)` in your ReactJS.NET config to use the debug version. The production version of React is much faster than the debug build, but it has less useful error messages if something does go wrong.
2021
* [#299](https://github.com/reactjs/React.NET/issues/299) - Use file hash to check for file changes before transpiling. *Thanks to [Torben Rahbek Koch](https://github.com/TorbenRahbekKoch)*
2122
* [#317](https://github.com/reactjs/React.NET/issues/317) - Switched to [Paul Knopf](https://github.com/pauldotknopf)'s branch of VroomJs (V8 for Linux / Mac OS) rather than maintaining our own fork

site/jekyll/getting-started/aspnetcore.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ layout: docs
44
title: Getting Started on ASP.NET Core
55
---
66

7-
Getting started with ReactJS.NET on ASP.NET Core requires a few more steps compared to previous versions of ASP.NET and MVC. A more fully featured tutorial will be released soon.
7+
Getting started with ReactJS.NET on ASP.NET Core requires a few more steps compared to previous versions of ASP.NET and MVC. If you want a step-by-step guide on configuring a brand new site, see [the ReactJS.NET tutorial for ASP.NET Core](/getting-started/tutorial.html).
88

9-
ReactJS.NET requires Visual Studio 2015 and ASP.NET Core RTM (final release). Additionally, ReactJS.NET does not support .NET Core at this point in time, so you will need to ensure your project is not referencing it. If you're creating a new website, use the "ASP.NET Core Web Application (.NET Framework)" project template. Otherwise, make sure your `project.json` references `net452` in its `frameworks` section, **not** `netcoreapp`.
9+
ReactJS.NET requires Visual Studio 2015 and ASP.NET Core RTM (final release). It is recommended to use .NET Framework, but ReactJS.NET also works with .NET Core.
1010

1111
Install the `React.AspNet` package through NuGet. After the package is installed, ReactJS.NET needs to be initialised in your `Startup.cs` file (unfortunately this can not be done automatically like in previous versions of ASP.NET with WebActivator). At the top of the file, add:
1212

@@ -66,4 +66,4 @@ Finally, add this to `Views\_ViewImports.cshtml` (or create it if it doesn't exi
6666
@using React.AspNet
6767
```
6868

69-
Once ReactJS.NET has been configured, you will be able to use [on-the-fly JSX to JavaScript compilation](http://reactjs.net/getting-started/usage.html) and [server-side rendering](http://reactjs.net/guides/server-side-rendering.html).
69+
Once ReactJS.NET has been configured, you will be able to use [on-the-fly JSX to JavaScript compilation](/getting-started/usage.html) and [server-side rendering](/guides/server-side-rendering.html).

site/jekyll/getting-started/tutorial_aspnet4.md

+39-18
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ So far we've been inserting the comments directly in the source code. Instead, l
296296

297297
```javascript
298298
var data = [
299-
{ Author: "Daniel Lo Nigro", Text: "Hello ReactJS.NET World!" },
300-
{ Author: "Pete Hunt", Text: "This is one comment" },
301-
{ Author: "Jordan Walke", Text: "This is *another* comment" }
299+
{ Id: 1, Author: "Daniel Lo Nigro", Text: "Hello ReactJS.NET World!" },
300+
{ Id: 2, Author: "Pete Hunt", Text: "This is one comment" },
301+
{ Id: 3, Author: "Jordan Walke", Text: "This is *another* comment" }
302302
];
303303
```
304304

@@ -355,6 +355,7 @@ namespace ReactDemo.Models
355355
{
356356
public class CommentModel
357357
{
358+
public int Id { get; set; }
358359
public string Author { get; set; }
359360
public string Text { get; set; }
360361
}
@@ -370,37 +371,40 @@ using ReactDemo.Models;
370371
371372
namespace ReactDemo.Controllers
372373
{
373-
public class HomeController : Controller
374-
{
375-
private static readonly IList<CommentModel> _comments;
374+
public class HomeController : Controller
375+
{
376+
private static readonly IList<CommentModel> _comments;
376377
377-
static HomeController()
378-
{
378+
static HomeController()
379+
{
379380
_comments = new List<CommentModel>
380381
{
381382
new CommentModel
382383
{
384+
Id = 1,
383385
Author = "Daniel Lo Nigro",
384386
Text = "Hello ReactJS.NET World!"
385387
},
386388
new CommentModel
387389
{
390+
Id = 2,
388391
Author = "Pete Hunt",
389392
Text = "This is one comment"
390393
},
391394
new CommentModel
392395
{
396+
Id = 3,
393397
Author = "Jordan Walke",
394398
Text = "This is *another* comment"
395399
},
396400
};
397-
}
401+
}
398402
399-
public ActionResult Index()
400-
{
401-
return View();
402-
}
403-
}
403+
public ActionResult Index()
404+
{
405+
return View();
406+
}
407+
}
404408
}
405409
```
406410

@@ -414,7 +418,7 @@ public ActionResult Comments()
414418
}
415419
```
416420

417-
The OutputCache attribute is used here to prevent browsers from caching the response. When designing a real world API, caching of API requests should be considered more carefully. For this tutorial it is easiest to simply disable caching.
421+
The `OutputCache` attribute is used here to prevent browsers from caching the response. When designing a real world API, caching of API requests should be considered more carefully. For this tutorial it is easiest to simply disable caching.
418422

419423
Finally we add a corresponding route in `App_Start\RouteConfig.cs`:
420424

@@ -461,6 +465,8 @@ ReactDOM.render(
461465
);
462466
```
463467

468+
Note that in a real app, you should generate the URL server-side (via `Url.Action` call) and pass it down, or use [RouteJs](http://dan.cx/projects/routejs) rather than hard-coding it. This tutorial hard-codes it for simplicity.
469+
464470
This component is different from the prior components because it will have to re-render itself. The component won't have any data until the request from the server comes back, at which point the component may need to render some new comments.
465471

466472
### Reactive state
@@ -566,6 +572,8 @@ To accept new comments, we need to first add a controller action to handle it. T
566572
[HttpPost]
567573
public ActionResult AddComment(CommentModel comment)
568574
{
575+
// Create a fake ID for this comment
576+
comment.Id = _comments.Count + 1;
569577
_comments.Add(comment);
570578
return Content("Success :)");
571579
}
@@ -973,9 +981,9 @@ var CommentBox = React.createClass({
973981
var newComments = comments.concat([comment]);
974982
this.setState({data: newComments});
975983
976-
var data = new FormData();
977-
data.append('Author', comment.Author);
978-
data.append('Text', comment.Text);
984+
var data = new FormData();
985+
data.append('Author', comment.Author);
986+
data.append('Text', comment.Text);
979987
980988
var xhr = new XMLHttpRequest();
981989
xhr.open('post', this.props.submitUrl, true);
@@ -1002,6 +1010,16 @@ var CommentBox = React.createClass({
10021010
});
10031011
```
10041012

1013+
We also need to update the `Comment` component to use `Remarkable` from either `global` or `window`, due to a bug in Remarkable:
1014+
```javascript{3}
1015+
var Comment = React.createClass({
1016+
rawMarkup: function () {
1017+
var md = new (global.Remarkable || window.Remarkable)();
1018+
var rawMarkup = md.render(this.props.children.toString());
1019+
return { __html: rawMarkup };
1020+
},
1021+
```
1022+
10051023
In the view, we will accept the list of comments as the model, and use `Html.React` to render the component. This will replace the `ReactDOM.render` call that currently exists in Tutorial.jsx. All the props from the current `ReactDOM.render` call should be moved here, and the `ReactDOM.render` call should be deleted.
10061024

10071025
```html{1,10-16,21}
@@ -1053,12 +1071,15 @@ namespace ReactDemo
10531071
public static void Configure()
10541072
{
10551073
ReactSiteConfiguration.Configuration
1074+
.AddScript("~/js/remarkable.min.js")
10561075
.AddScript("~/Scripts/Tutorial.jsx");
10571076
}
10581077
}
10591078
}
10601079
```
10611080

1081+
Note that we need a copy of Remarkable in order to load it for server-side rendering. In a production app you'd probably use Bower or npm for this, but for our tutorial you can just [download the file from CDNJS](https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js) and save it into `~/js`.
1082+
10621083
That's it! Now if you build and refresh your application, you should notice that the comments box is rendered immediately rather than having a slight delay. If you view the source of the page, you will see the initial comments directly in the HTML itself:
10631084

10641085
```html

site/jekyll/guides/server-side-rendering.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ to wait for all the JavaScript to load before seeing the web page.
99

1010
To use server-side rendering in your application, follow the following steps:
1111

12-
1 - Modify `App_Start\ReactConfig.cs` to reference your components:
12+
1 - Modify `App_Start\ReactConfig.cs` (for ASP.NET MVC 4 or 5) or `Startup.cs` (for ASP.NET Core) to reference your components:
1313

1414
```csharp
1515
namespace MyApp
@@ -72,12 +72,14 @@ code.
7272
The server-rendered HTML will automatically be reused by React client-side,
7373
meaning your initial render will be super fast.
7474

75+
If you encounter any errors with the JavaScript, you may want to temporarily disable server-side rendering in order to debug your components in your browser. You can do this by calling `DisableServerSideRendering()` in your ReactJS.NET config.
76+
7577
For a more in-depth example, take a look at the included sample application
7678
(**React.Samples.Mvc4**).
7779

7880
5 - Server-side only rendering
7981

80-
If there is no need to have a React application client side and you just want to use the server side rendering but without the React specific data attributes call `Html.React` and pass serverOnly parameter as true.
82+
If there is no need to have a React application client side and you just want to use the server side rendering but without the React specific data attributes, call `Html.React` and pass serverOnly parameter as true.
8183

8284
```csharp
8385
@Html.React("HelloWorld", new
@@ -86,7 +88,7 @@ If there is no need to have a React application client side and you just want to
8688
}, serverOnly: true)
8789
```
8890

89-
And the Html mark up will look like the one following which is a lot cleaner. In this case there is no need to load the React script or call the `Html.ReactInitJavaScript()` method.
91+
And the HTML will look like the one following which is a lot cleaner. In this case there is no need to load the React script or call the `Html.ReactInitJavaScript()` method.
9092

9193
```html
9294
<div id="react1">

site/jekyll/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ id: home
1818
[React](http://facebook.github.io/react/) and
1919
[JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) from C# and
2020
other .NET languages, focusing specifically on ASP.NET MVC (although it
21-
also works in other environments). It assumes you already have some basic
22-
knowledge about React. It is cross-platform and can run on Linux via Mono.
23-
Now with support for [ASP.NET 5 Beta](/getting-started/aspnet5.html)!
21+
also works in other environments). It supports both ASP.NET 4 (with MVC 4 or 5),
22+
and ASP.NET Core MVC. It is cross-platform and can run on Linux via Mono
23+
or .NET Core.
2424
Take a look at [the tutorial](/getting-started/tutorial.html) to see how
2525
easy it is to get started with React and ReactJS.NET!
2626
</p>

0 commit comments

Comments
 (0)