A Brief Overview of React.js

React is a user interface library that was developed at Facebook. React is written in different components and follows the principles of immutable data. It’s often used in enterprise applications, and it makes creating single page applications easier since they have a higher speed thanks to the virtual DOM. This means it writes to the browser DOM only when it is needed, instead of re-rendering an entire view when a change is made.

Virtual DOM

React creates an in-memory DOM where it only renders different parts of the DOM when a change occurs.

JSX

React utilizes JSX, which is a JavaScript extension syntax that allows you to quote HTML.

Babel

Babel is a transpiler that transpiles JavaScript code. It works for JSX as well as ES6 and beyond. Babel converts React’s JSX and ES6 to something the browser can use.

Components

React applications consist of a collection of components. Components are small user interface elements that display data as it changes over time. Used together, these components create entire user interfaces.

Component Lifecycle

Component lifecycles allow you to add libraries and load data at specific times. They also help improve the speed of an application, with lifecycle methods that you can override to run code a specific times in the process.

Mounting methods are called when an instance of a component is being created:

  • getInitialState()
  • componentWillMount()
  • componentDidMount()

Updating methods occur when a change happens to props or state:

  • componentWillReceiveProps()
  • shouldComponentUpdate()
  • componentWillUpdate()
  • render()
  • componentDidUpdate()

Unmounting methods are called when a component is being removed:

  • componentWillUnmount()

 

Deploying a React App to GitHub Pages

Earlier today, I worked on putting together this Sticky Note App, in an effort to get more comfortable with React.js. The application uses React.js, React DOM, and React Draggable.

After completing my application, I was about to tackle deployment with Heroku, since I’ve become pretty familiar with deploying various applications that consist of different stacks on Heroku.

However, this application was a lot simpler, so it seemed like using Heroku would have been a little excessive, especially since there’s no backend component for this application.

So I decided to tackle deploying the application via GitHub pages – which is already one of my favorite ways to deploy simple applications since I host all my repos there as well.

The first step I did, was use the create-react-app command in my terminal, where I then moved the various components of my simple React application. Then I followed the following steps:

Step 1

Edit package.json by adding a homepage

"homepage": "https://[insert username].github.io/[insert project repo name]"

Step 2

Run npm install --save-dev gh-pages

Step 3

Edit package.json by adding a predeploy and deploy script:

"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}

Step 4

Run: npm run deploy

And there you have it, a simple enough solution for deploying those simple enough React applications.

A Brief Overview of Node.js and Express.js

If you’ve worked with JavaScript frameworks and libraries, chances are that you’ve heard of Node.js and Express.js. So for those who are unfamiliar to these terms – what exactly are they?

Node.js

Node.js is an open-source JavaScript runtime environment, that uses Google’s V8 JavaScript engine, where you can build server applications. Node.js is not a framework, although it has many modules that are written in JavaScript. It has event-driven architecture that is capable of asynchronous I/O, otherwise none as a form of input/output processing that allows other processing to continue before the transfer of data has finished.

Express.js

Express.js is a web application framework for Node.js, that’s used for building APIs. It is also known for being a backend component of the MEAN stack.

I’ve worked with Node.js and Express.js to create APIs, so I feel like I can never think about one of them without having the other one come to mind.

Getting Started with Rails

For anyone that’s new to Rails, there are a couple of tutorials out there that I’d highly recommend:

I’d say repeating the Rails Guide tutorial several times first is a good place to start, then moving to Michael Hartl’s tutorial and completing that a few times, which will give you a much better understanding of even more complex Rails concepts.

I’m a strong advocate for learning through repetition, especially if you’re new to programming or don’t have a background in computer science.

Using MAMP to run WordPress Locally

If you have a WordPress site and would like to update the theme or work on developing any other aspect of the site locally, you can do so by following these steps:

  • Download and install MAMP, which is software that installs a local server environment on your computer. MAMP gives you the ability to install Apache, PHP, and MySQL on your local machine. You can find out more about installing MAMP on the WordPress documentation website.
  • Once MAMP is installed, you can copy over your entire website to your local machine.
  • Open MAMP and specify the root of the folder for the site you want to run. Then start the servers.
  • Next update the wp-config-php file so that it specifies the local host as the host, as opposed to the domain name: define('DB_HOST', 'localhost');
  • Then access the MAMP welcome screen and open up the local phpMyAdmin.
    • Find the “create new database field” and enter in the name of the backup database from the live website that you are going to import.
  • When you access the site in the browser, you should be able to see the homepage although all the other pages are probably broken. This is because you need to update the siteurl and home configurations.
    • In phpMyAdmin, select the new database
    • Select the “wp_options” table
    • Search for “siteurl” within the “option_name” column
    • Edit the “siteurl” so it points to the localhost
    • Next, search for “home” within the “option_name” column
    • Edit the “home” item so it points to the localhost as well
  • Next, visit the homepage for the locally installed site and ta-da, it should work fine. You are also able to login with the wp-admin by using the usual admin credentials you use for the live website. Now you can edit themes, update plugins, and test out other features locally without worrying about breaking your live website.