A ReactJS Module for Building Sitecore Components with React

A ReactJS Module for Building Sitecore Components with React

A ReactJS module for building Sitecore components with React and ReactJS.NET.

Sitecore.React

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}

Download Details:

Author: GuitarRich

Source Code: https://github.com/GuitarRich/sitecore.react

react reactjs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

Routing in React without React-Router

I have been using React JS in my projects for quite some time now and am used to managing routing in my app using the react-router package. I have always been keen on having as little dependencies in my apps as possible, so, I always felt perturbed by the use of this particular package in simpler apps which did not have complex routes.

The Ugly Side of React Hooks

In this post, I will share my own point of view about React Hooks, and as the title of this post implies, I am not a big fan.

ReactJS: The Javascript Developer’s Guide

This article will walk you through the concepts you would need to know to step into the world of widely used ReactJS.