hostmonster-Host Unlimited Domains on 1 Account   coolhandle offering reliable webhosting since 2001
Unlimited Hosting Space - FREE Site Builder   Smart Website Solutions for Your Small Business=

Creating Universal Windows Apps With React Native

Sponsored Article
Creating Universal Windows Apps With React Native

React.js1 is a popular JavaScript library for building reusable UI components. React Native2 takes all the great features of React, from the one-way binding and virtual DOM to debugging tools3, and applies them to mobile app development on iOS and Android.

With the React Native Universal Windows platform extension, you can now make your React Native applications run on the Universal Windows families of devices, including desktop, mobile, and Xbox, as well as Windows IoT, Surface Hub, and HoloLens.

In this code story, we will walk through the process of setting up a Universal Windows project for React Native, importing core Windows-specific modules to your JavaScript components, and running the app with Visual Studio.


Installing React Native For Windows Link

Installing the React Native Universal Windows platform extension is easy, whether you want to add the Windows platform to your existing app, or you want to start from scratch building an app just for Windows.

Adding React Native for Windows to Existing Projects Link

React Native developers may be familiar with RNPM5, a tool initially built to simplify the process of adding native dependencies to React Native projects. RNPM has a great plugin architecture upon which the React Native for Windows command line tools were built.

To start, make sure you have RNPM installed globally.

npm install -g rnpm

Once RNPM is installed, install the Windows plugin for RNPM and initialize your project.

npm install --save-dev rnpm-plugin-windows
rnpm windows

The windows command will do the following:

  • Install react-native-windows from NPM6,
  • Read the name of your project from package.json,
  • Use Yeoman7 to generate the Windows project files.

The RNPM plugin architecture searches your local package.json dependencies and devDependencies for modules that match rnpm-plugin-*, hence the --save-dev above.

Head to GitHub8 for more information on rnpm-plugin-windows.

Creating a React Native for Windows Project from Scratch Link

You have a few different options to create a React Native Universal Windows project from scratch. If your eventual intent is to also build apps for iOS and Android in the same code base, then the recommendation is to first use the existing tutorial9 to set up your React Native project, and then follow the steps above. E.g.,

npm install -g react-native-cli
react-native init myapp

Note: the react-native-windows NPM package is only compatible with the latest versions of react-native, from version 0.27 onwards.

Otherwise, you can easily set yourself up with npm init.

mkdir myapp
cd myapp
npm init
npm install --save-dev rnpm-plugin-windows
rnpm windows

Note: the default behavior for choosing the version of react-native-windows is to install the latest version if the package.json does not yet have a react-native dependency. Otherwise, if a react-native dependency already exists, the plugin will attempt to install a version of react-native-windows that matches the major and minor version of react-native.

The Windows plugin for RNPM will automatically install the react-native and react peer dependencies for react-native-windows if they have not yet been installed.

React Native For Windows Project Structure Link

There are a few boilerplate files that get generated for the Universal Windows App. The important ones include:

  • — This is the entry point to your React application.
  • windows/myapp.sln — This is where you should start to launch your app and debug native code.
  • windows/myapp/MainPage.cs — This is where you can tweak the native bridge settings, like available modules and components.

Here’s the full output:

├── windows
    ├── myapp.sln
    ├── myapp
        ├── Properties
            ├── AssemblyInfo.cs
            ├── Default.rd.xml
        ├── Assets
            ├── ...
        ├── App.xaml
        ├── App.xaml.cs
        ├── MainPage.cs
        ├── project.json
        ├── Package.appxmanifest
        ├── myapp_TemporaryKey.pfx

We ship the core C# library for React Native as source on NPM. Having direct access to the source will help with debugging and making small tweaks where necessary. As long as the core ships as source, third party modules will also need to follow suit (although their dependencies may be binary). We’ll be working with the React Native community on react-native link support to make dependency management as simple as possible. Instructions for how to link dependencies are available on GitHub10.

Building And Extending Apps For The Windows Platform Link

The core components and modules for React Native are imported as follows:

import {
} from 'react-native';

Currently, the same goes for Android- and iOS-specific modules, i.e.:

import {
} from 'react-native';

Since Windows is a plugin to the framework, core modules specific to Windows are imported from react-native-windows, i.e.:

import {
} from 'react-native-windows';

So, a typical imports section of a React component with a mixture of core and Windows-specific modules will look like:

import React, { Component } from 'react';
import {
} from 'react-native';
import {
} from 'react-native-windows';

There is a list of the core modules available on React Native for Windows on GitHub11.

There are multiple ways to add conditional behavior to your apps based on the platform. One way that you might already recognize is the use of the *.platform.js pattern, i.e., index.[android|ios|windows].js. The node-haste12 dependency graph will choose the filename that matches the active platform choice, and fallback to the filename without any platform indicator, if available. E.g., if you have files and MyComponent.js, node-haste will choose MyComponent.js for Android and iOS and for Windows.

Another way is to use conditional logic inside a component, as demonstrated in the simple component below.

import React, {Component} from 'react';
import {
} from 'react-native';

class HelloComponent extends Component {
  render() {
    var text = "Hello world!";
    if (Platform.OS === 'android') {
      text = "Hello Android!";
    } else if (Platform.OS === 'windows') {
      text = "Hello Windows!";
    return (

Facebook has a very good article on cross-platform design with React Native at makeitopen.com13.

Running The Universal Windows App Link

There are a few options for running your React Native Universal Windows app. The easiest way, for now, is to launch the app in Visual Studio. After initializing the project, open the Visual Studio solution at ./windows/myapp.sln in Visual Studio 201514 (Community edition is supported). From Visual Studio, choose which platform you want to build for (x86, x64, or ARM), choose the target you want to deploy to, and press F5. We are still working on deployment from the command line, but work to enable a run-windows command to the RNPM plugin is underway.

The instructions for running React Native UWP apps, both from Visual Studio and from the CLI, will be evolving on GitHub15. If you have any problems getting started with building or running your React Windows application, reach out on Discord16 or open an issue17. We look forward to hearing your feedback and reviewing your contributions18!

More Hands-On With Web And Mobile Apps Link

Check out these helpful resources on building web and Mobile Apps:

For further updates on the topic and new features, please view the original documentation25.

Footnotes Link

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21!lang=1049
  22. 22!lang=1049
  23. 23
  24. 24
  25. 25

↑ Back to top

Tweet itShare on Facebook

Eric Rozell is a Senior Software Engineer on the Developer Experience team at Microsoft.  He currently leads the effort to bring React Native to the Universal Windows Platform and is a contributor to Rx.NET and RxJS.

Related Articles


Finding Better Mobile Analytics


Driving App Engagement With Personalization Techniques


The Building Blocks Of Progressive Web Apps

  • 1 Comment
  1. 1

    Maybe could be interesting to use React + Electron for Universal Desktop applications as well.

Leave a Comment Click here to cancel reply.

↑ Back to top

Article source:


Submit a Review

If you want a picture to show with your review, go get a Gravatar.

1&1 has shared hosting and dedicated hosting solutions for every budget and free domains with all hosting packages!  StartLogic - Affordable hosting: Free setup/domain, unlimited emails, PHP, mySQL, CGI, FrontPage. As low as $3.95/month
Cloud ecommerce platform delivers more traffic, higher conversion and unmatched performance

© Copyright 2008 Tyconia International, Inc. All Rights Reserved.