1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Build an App with React Suspense, Hooks, and Context Workshop Setup

    Michael ChanMichael Chan
    reactReact

    If you're part of the live Build an App with React Suspense, Hooks, and Context Workshop, this setup video is for you.

    I show you where the project repo is, how to navigate the project, switch lessons, and a little cheat that I'm doing with Yarn Workspaces to use an unpublished version of react-cache. If you'd like to learn more about building react-cache from source, watch Build React from Source

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Michael Chan: Hey there Egghead friends. My name is Michael Chan, also known as Chantastic. I am over the moon about this course. I can't tell you how excited I am to be working with Egghead, to be meeting you, doing this course on React Suspense.

    I saw that it sold out in less than 12 hours, which has me really excited about your excitement for the topic. I hope to do that a lot of justice. As a precursor, this course is a little bit advanced. Not so much that you wouldn't be able to follow along if you were a newcomer to React, but I don't spend a lot of time talking about certain things, like how you would write a component, or how they compose together.

    I do talk about how all of those concepts interplay with Suspense. We talk about Suspense and how that impacts component organization. We talk about lazy loading and how that impacts component organization. A lot of these things are how you would modify your existing thinking about React and organization structure and component relationships in a world with Suspense and lazy loading.

    That's the big takeaway that I hope you get from the course. Beyond that, I will show you all of my favorite tips and tricks for composing components together after we get through the main Suspense stuff.

    Where is all this going to live? Great question. I am working right now, actively, feverishly putting in all of the disparate ideas and notes and things that I've written all into this one repo. I'm hoping that it's a really good way for you to explore the concepts.

    I am going to be working from this repository for the course, so I wanted to show you how to get in there, get around. If you want to watch it, you'll be able to see material as I put it in.

    Where is it? First of all, it's on GitHub, under my user, chantastic/react-suspense-course. If you wanted to go directly there, it's just github.com/chantastic/react-suspense-course, with the dashes in between the words.

    Here, I have a "Read Me," that tells you how to contact me if you want to get a hold of me, what the goals of the course are, why you should care, etc. At the bottom here, I have installation and usage instruction.

    That's what we're going to follow along with today, because I want you to be ready to hit the ground running so we can hit all of those important Suspense topics right off the bat. We're going to go through that. Then I'm going to show you the general organization of the app, so that's not a surprise to you either.

    OK, OK. Let's see. The first thing is, we just need to clone this repository, run Yarn to get all the dependencies, and then Yarn Start will do it.

    Just for those who are curious, I started this from a Create React App. Very minimal modifications -- just took out a couple of things we didn't need, so it's all just running the latest React scripts with the latest React and ReactDOM versions. Nothing fancy going on here. If you're familiar with React scripts and Create React App, you're good to go. This should feel very natural for you.

    Let's get that URL, copy that, and I'm going to move this aside here. My new Catalina backdrop. Then we are going to find the directory that we want and code/chantastic, and we're just going to getClone and pace our thing. It's going to clone it as ReactSuspenseCourse. It happens real fast.

    I am going to just open that in code. The editor that I'll be using is VS Code. You can use whatever editor...It looks like I opened the wrong thing. Oh, I do this all the time. I forgot the CD in the directory. CD/ReactSuspenseCourse. Then I'm going to open it up in code.

    OK, there we go. That's right. Then, let's see. I'm going to run Yarn. That's going to fetch all of the dependencies. Yarn is the default package manager for Create React App.

    Also, it's going to be critically important for one piece of our setup. I'll show you that as soon as we get all these dependencies...

    Michael: and loaded and talk about them. It is taking a while. It might take a while, and this is why it's important to do this beforehand.

    OK, so we're done. You're probably thinking, "Dang, that's a lot of dependencies." Those are just Create React App dependencies. There's nothing special going on beyond the Create React App setup here, and I'll prove that to you just by showing you code.

    From here, we're going to run YarnStart. If everything worked, that should open up a browser for us at localhost:3000, if it's available. Great. We have that. I can close this up now. Now, I didn't do this appropriately, but when you start, you should see Lesson 1. It'll just say, "Lesson."

    The way that this is set up is that there is this source directory, which you should be familiar with as a React App user. That just has one index file. It's going to input a lesson as app and then render that app to the DOM. What this does is it allows us to easily switch between lessons.

    When I decide that it's time to go to Lesson 2, you can just switch this. I hit Save, and then that will get you to the starting point for Lesson 2. That is the first thing, is this is how you change lesson in here. You don't have to restart a server. You're just going to change that number, which is really great.

    That takes us to the Lessons directory. So far, I only have five of the lessons in here. It's going to be significantly more than that. When you open those up, you'll see an index.js file. That is going to be what we're using as the application.

    You can see here, it's just Lesson 1, and then also a readme. That readme is going to give you instructions based on the current lesson, Lesson 1, on how to get to Lesson 2 -- the changes you need to make. Consequently, the application for Lesson 2 is the solution to Lesson 1.

    Hopefully, that all makes sense. I'm going to be driving us through that process on Wednesday, so you don't really need to worry about that unless you're following the project along, or doing it outside of the workshop.

    I want to talk to you about one way that I am cheating in this project. I want to show all my cards right upfront. Suspense has been in React for almost a year now. However, they have not provided a React cache implementation for different libraries to use as a reference.

    At some point, I'm assuming at React Conf, they will announce that they have a React cache implementation, so that other libraries like Apollo and whatnot can use this as a reference for their data fetching.

    In order to use this today, with the modern versions of React, we have to build it from source. I made a video on Akit to show you how to do that -- to show you that it's really not that complicated or that magical.

    Now, in order for us to require it, as we eventually will, as just importing the package react-cache, I've done a little bit of trickery here using Yarn. Yarn has this really cool feature called Yarn Workspaces.

    What they allow you to do...This isn't the article that I want. What they allow you to do is they allow you to establish a directory on your file system, inside of your project, that acts just like an npm package, even though it's not published to npm.

    Instead of using a relative path to import react-cache, I've set it up using Yarn Workspaces so that we have this react-cache package. It uses the source that is the recent react-cache development version that works with the latest version of React.

    Let's see. In package.json, we're just saying, "Hey, we have an additional workspace in this repository called react-cache, right here, with an index file. Now, in our application, when we have an example that says we want to import react-cache, like we would from npm, just resolve that to this local directory. Don't try to resolve it via vn.

    A little bit of trickery there just because this is a very new feature. Probably in the next two weeks, we'll get a implementation version of this that inaudible . We're just a little bit ahead of the curve. I've tried to make it as reasonable as possible for you to use this, and then make a little tweak down the road. I hope that helps.

    If you have any questions about this project, about the course, I am so happy to help. You can hit me up on Twitter @chantastic, or via email, which is, if I can find it, all linked here on that repository, chantastic/reactsuspensecourse.

    I'm so excited to see you on Wednesday. I cannot hardly wait. Feel free to hit me up on these mediums and just say hi, introduce yourself. We're going to have a lot of fun on Wednesday. Thanks so much. See you then.