Skip to content
A ReactJS module for building Sitecore components with React
C# HTML PowerShell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
NuGet
build Update all Nuget Packages to latest version Nov 11, 2019
icon Updates for SUGCON May 16, 2017
src/Foundation/React
.gitignore Added folder location and readme for building locally. Oct 7, 2016
CSharpGuidelines.Layer.DotSettings
CSharpGuidelinesAnalyzer.config Update all Nuget Packages to latest version Nov 11, 2019
LICENSE
README.md Update all Nuget Packages to latest version Nov 11, 2019
Sitecore.React.sln
Sitecore.React.sln.DotSettings
appveyor.yml
azure-pipelines.yml Moving build over to devops Nov 11, 2019
nuget.config
pack.ps1 Bumped version numbers Jun 27, 2017

README.md

Sitecore.React

NuGet version

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.

Features

  • On the fly Jsx to JavaScript compilation via Babel and ReactJS.NET
  • Support for pre-built/transpiled
  • Server-side component rendering. Initial renders are super-fast and great for SEO
  • Full support for datasources, personalization and testing

Getting Started

  • 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="//fb.me/react-15.0.1.js"></script>
  <script src="//fb.me/react-dom-15.0.1.js"></script>
  @Scripts.Render(Sitecore.React.Configuration.Settings.ReactBundleName)
  • To add a placeholder to the component use:
{this.props.placeholder.KEY}

Replace KEY with the placeholder key you want to create.

  • To make the placeholder dynamic, prepend the key with $Id.
{this.props.placeholder.$Id.KEY}
You can’t perform that action at this time.