TNS
VOXPOP
Will JavaScript type annotations kill TypeScript?
The creators of Svelte and Turbo 8 both dropped TS recently saying that "it's not worth it".
Yes: If JavaScript gets type annotations then there's no reason for TypeScript to exist.
0%
No: TypeScript remains the best language for structuring large enterprise applications.
0%
TBD: The existing user base and its corpensource owner means that TypeScript isn’t likely to reach EOL without a putting up a fight.
0%
I hope they both die. I mean, if you really need strong types in the browser then you could leverage WASM and use a real programming language.
0%
I don’t know and I don’t care.
0%
Serverless / Software Development

How to Build a Serverless, SEO-Friendly React Blog

May 1st, 2017 12:00pm by
Featued image for: How to Build a Serverless, SEO-Friendly React Blog

Roger Jin
Roger Jin is a developer and technical writer at ButterCMS where he focuses on tools to make developers’ lives easier. Mixing his passion of programming and education, he writes articles focusing on serverless development, microservices, and much more. He develops mostly with React, Node.js, Elixir, and Ruby.

Serverless application architectures are gaining in popularity and it’s no mystery why. Developers are able to build and iterate on products faster when they have less infrastructure to maintain and don’t need to worry about server maintenance, outages, and scaling bottlenecks.

In this tutorial, we are going to show you how to build a serverless, CMS-powered blog using React, ButterCMS, and built-in prerendering through Netlify. The finished code for this tutorial is available on Github.

ButterCMS is a hosted API-based CMS and content API that lets you build CMS-powered apps using any programming language including Ruby, Rails, Node.js, .NET, Python, Phoenix, Django, Flask, React, Angular, Go, PHP, Laravel, Elixir, and Meteor. Butter lets you manage content using a hosted dashboard and integrate it into your front-end of choice with our API — you can think of Butter as similar to WordPress except that you build your website in your language of choice and then plug-in the dynamic content using an API.

Netlify is a static website hosting service that streamlines integration with prerendering services like Prerender.io, SEO.js, and Brombone.

Getting Started

We’ll use the Create React App starter kit.

Install Create React App:


Then create the boilerplate for our app:

Adding Routing

Our blog needs two pages: one for listing all posts and another for displaying individual posts. Create BlogHome.jsand BlogPost.js components in the src directory:



Create React App doesn’t offer routing out-of-the-box so we’ll add react-router:


In the source folder, create a new file called routes.js. We’ll create routes for the blog home page with and without page parameters, as well as the individual post page:

Next, we’ll update index.js so it uses our routes when initializing the application:

And finally, we’ll update App.js so it nests child components specified in our routes:

Building the Blog

We’ll use ButterCMS to build our blog. ButterCMS provides content APIs for blog posts, categories, tags, and authors.

First, we’ll install the ButterCMS Node.js API client:


We’ll then update ‘BlogHome’ to fetch posts from ButterCMS and render them. Use the API token in the example below or get your own by signing into ButterCMS with Github.

Next, we’ll update BlogPost.js to fetch and display posts based on the route: