How to Setup a New React Native Mac App

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Building React Native Apps for Mac course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Building React Native Apps for Mac, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Building React Native Apps for Mac
  • [00:00 - 00:09] Hi, in this lesson I'll just create a bare bones app for our course. I'm just going to follow the instructions in the lesson.

    [00:10 - 00:19] So I have it open here and I have my terminal here. So before installing or creating our application we need to have certain things installed on your machine.

    [00:20 - 00:37] You need to have Homebrew, which is a package manager that is going to allow you to install some of the tools. You need to have Xcode, you need to download it from the App Store, you open it , you accept all the terms and you should be good to go.

    [00:38 - 00:45] You need to have a Node.js installation. So I recommend that you use Volta, which is a tool manager.

    [00:46 - 00:58] It just allows you to have different installations of Node.js on a single machine. And once you install it, you have Volta, install Node 15 or whatever version you want.

    [00:59 - 01:05] I had a little bit of troubles with Volta because I'm using a new Mac. So I'm using NVM, which is a different manager.

    [01:06 - 01:11] But you can use whatever you want. As long as you have a working Node.js installation is fine.

    [01:12 - 01:18] You also need to have Ruby installed. By default it comes with all Macs.

    [01:19 - 01:30] If you have any type of problem, you can just run brew, install Ruby after you have installed homebrew and they will try to reinstall it for you. And finally, you also need a code editor.

    [01:31 - 01:40] So I'm using VGS code, but anything you want as well works fine. So we need to have certain package managers.

    [01:41 - 01:51] One's going to be for the JavaScript side of things and one's going to be for the native dependencies. So Yarn is the package manager that it will use for the JavaScript dependencies .

    [01:52 - 02:01] If you're using Volta, you can just install it with Volta, install Yarn. If not, you can just install it with NPM-G Yarn.

    [02:02 - 02:08] This is going to do a global installation in your machine. I really have it installed.

    [02:09 - 02:16] So it's there. You also need CocoaPods, which is a package manager for the native dependencies .

    [02:17 - 02:23] So you can install it via sudo Jme install CocoaPods. I already have it on my machine, so I'm not running all of the commands.

    [02:24 - 02:30] Everything is kind of set up, but you should just follow the instructions on the lesson. Good.

    [02:31 - 02:42] So now that we have all the tooling necessary, we can actually create a project . So I'm just going to take the command that I put in the console or in the lesson and paste it on my console.

    [02:43 - 02:50] So I just need to replace the project name. I'm just going to go for something simple, building apps.

    [02:51 - 03:01] And here you will notice that I set a specific version. So as a time of now, when I wrote the course, this is the latest version.

    [03:02 - 03:11] And it's important that the React Native version and the macOS version match, right? Because otherwise you might have some issues in there.

    [03:12 - 03:21] But I think the in-it template also kind of does some recognition. But just in case if you see anything that's not working, that could be the problem.

    [03:22 - 03:24] So this is right now installing. We're going to give it a little bit.

    [03:25 - 03:57] So this is the very React Native project. So I'm just going to run a couple more things.

    [03:58 - 04:07] So I'm just going to cd into the directory that was created for me. And I'm going to execute the React Native macOS in it command.

    [04:08 - 04:13] So this is going to prepare the project to run in macOS. We're also going to give it a little bit of time.

    [04:14 - 04:44] So after that's done, our project is finally ready to run on macOS. So we will just use the command NPX, React Native, run macOS.

    [04:45 - 04:49] So a new window will pop up in a little bit. That's the package, that's Metro.

    [04:50 - 05:12] So that takes care of taking our JavaScript or TypeScript. And it can compile, set it and make sure everything is working properly in the simulator or in the mobile device because JavaScript needs to be compressed and a lot of things need to work on different JavaScript engines.

    [05:13 - 05:18] So don't close that window. If you close it, your application will just stop working.

    [05:19 - 05:25] But you will see we need to wait a little bit because this is all the native code that gets compiled. So let's just give it a little bit.

    [05:26 - 05:50] So hopefully if everything went alright, you should now have a small window with a brand new application, which is our app. It's really cool.

    [05:51 - 06:01] So I'm just going to open the project on Visual Studio Code. I'm just going to do it from the terminal, but there are many ways to do this.

    [06:02 - 06:14] And I'm just going to go into the app.js file. And I'm just going to change some text a little bit just to show, just to make sure that everything is working right.

    [06:15 - 06:25] So where it says edit blah, blah, blah, blah, I'm just going to change. Hello world.

    [06:26 - 06:35] And that's it. You will see that on the package, it compile our index.js file.

    [06:36 - 06:47] So every time we make any changes, metrics, just repackages our JavaScript and send this back to the application, which is really cool. So we're going to go a step further here.

    [06:48 - 07:02] The idea is that we're not just going to start coding, but actually provide you with all of the tools that you would use in a real world project. So we're just going to add some extra commands that are going to make the life easier down the road.

    [07:03 - 07:10] So we need to go to the package.json file. And here I will just copy and paste it.

    [07:11 - 07:24] We added three commands, the macOS command, which is just shortcut to start the app. The macOS colon install command that will install all the native dependencies for us.

    [07:25 - 07:30] And the new command. So sometimes things might get a little bit weird.

    [07:31 - 07:39] They might get a little bit broken. So what you want to do is just clear the cache, clear all the dependencies and just kind of start again.

    [07:40 - 07:45] That should fix a lot of problems. So we're just going to make a shorthand for it in case something happens.

    [07:46 - 07:59] So if I need to call any of these commands, I can just go into the terminal and I can just say, yarn macOS, for example. I'm sorry, let me save it.

    [08:00 - 08:07] And it's just going to run that command. So just a nice way to do certain things.

    [08:08 - 08:14] So another thing that we're going to add into a project is TypeScript. TypeScript is JavaScript with types.

    [08:15 - 08:24] It gets a little bit more complex than that. But it not only gives us types, it gives us auto completion and code navigation and a lot of good stuff.

    [08:25 - 08:38] So it's just a very sensible choice for your application, especially as it grows, is going to help you a lot. So in order to install TypeScript, we're going to create a new file in the root folder of our project.

    [08:39 - 08:48] We're going to call it the config.json. And I'm just going to take the configuration that I put on the lesson.

    [08:49 - 08:52] Just going to copy that. And I'm going to paste it.

    [08:53 - 08:58] So you can see there's a lot of options in here. I kind of set up everything for you already.

    [08:59 - 09:05] So you can just use it. But you can actually configure how the language behaves quite a bit.

    [09:06 - 09:11] Great. So now that we have TypeScript configured, we can actually start creating some TypeScript code.

    [09:12 - 09:17] So in order to do this, I'm going to go to the root folder. And I'm going to create a new folder in there.

    [09:18 - 09:25] It's going to be called CRC for source. Inside of it, I'm going to create a new app.tsx file.

    [09:26 - 09:34] So I'm just going to take the code that I put on the lesson, copy it, paste it. So you can see it's just a simple component.

    [09:35 - 09:38] We'll go over a component in a little bit. Don't worry about it.

    [09:39 - 09:43] But you will see that your editor might complain about this. It says it doesn't know what React is.

    [09:44 - 09:48] It doesn't know what React native is. So this is TypeScript complaining about this stuff.

    [09:49 - 09:53] So we're just going to go into the console. I'm just going to clear this.

    [09:54 - 10:07] And we're going to add this, this command. So we're going to do R, yarn, add, dash, dash, depth, types, forward slash, react, and types, forward slash, react native.

    [10:08 - 10:17] So what this is going to do, it's going to fetch the types for both React and React native for TypeScript. So we get type completions and type safety on both of them.

    [10:18 - 10:26] So now if we go back to the editor, then you'll see that both errors have disappeared. So I'm just going to save this file.

    [10:27 - 10:34] Next, I'm just going to go into the index.js file. So this file is kind of the entry point of the application.

    [10:35 - 10:42] So the native code is going to call this file first in order to monitor application. I'm just going to copy and paste again.

    [10:43 - 10:54] Not much changes except the import of our app. So instead of importing app.js, I am now importing from the source app.tsx.

    [10:55 - 11:05] So if I save this, and I go back into our application, then you can see hello form TypeScript, which is what we wanted. And that's it.

    [11:06 - 11:16] We're pretty much set to go. So on the next lessons, we will start with state management and then move to them in with tailwind, but we now have a working application.