A ReactJS module for building Sitecore components with React and ReactJS.NET.
The module has 2 parts. A Sitecore package that installs the required JsxControllerRendering
and JxsViewRendering
templates, and the Nuget package for use in your projects. This adds the required pipeline processors and components to render the React Jsx files as Sitecore renderings.
Install the NuGet package
Install-Package Sitecore.React
Install the Sitecore package
Create your JsxControllerRendering
controller and action
public SampleReactController : Controller
{
public ActionResult SampleReactRendering()
{
var data = new {
Title = FieldRenderer.Render(Sitecore.Context.Item, "Title"),
Text = FieldRenderer.Render(Sitecore.Context.Item, "Text")
};
return this.React("~/views/SampleReact/SampleReactRendering.jsx", data);
}
}
Create your Jsx component
var SampleReactRendering = React.createClass({
render: function() {
return (
<div>
<h1 dangerouslySetInnerHTML={{__html: this.props.data.Title}}></h1>
<div dangerouslySetInnerHTML={{__html: this.props.data.Text}}></div>
</div>
);
}
});
Create the rendering item in Sitecore and assign to an items presentation
Add the React JavaScript links and the Jsx bundle to your main layout
<script src="https://github.com/GuitarRich/sitecore.react/raw/master//fb.me/react-15.0.1.js"></script>
<script src="https://github.com/GuitarRich/sitecore.react/raw/master//fb.me/react-dom-15.0.1.js"></script>
@Scripts.Render(Sitecore.React.Configuration.Settings.ReactBundleName)
{this.props.placeholder.KEY}
Replace KEY with the placeholder key you want to create.
$Id.
{this.props.placeholder.$Id.KEY}