Remix Fundamentals

Rate this content
Bookmark

Building modern web applications is riddled with complexity And that's only if you bother to deal with the problems


Tired of wiring up onSubmit to backend APIs and making sure your client-side cache stays up-to-date? Wouldn't it be cool to be able to use the global nature of CSS to your benefit, rather than find tools or conventions to avoid or work around it? And how would you like nested layouts with intelligent and performance optimized data management that just works™?


Remix solves some of these problems, and completely eliminates the rest. You don't even have to think about server cache management or global CSS namespace clashes. It's not that Remix has APIs to avoid these problems, they simply don't exist when you're using Remix. Oh, and you don't need that huge complex graphql client when you're using Remix. They've got you covered. Ready to build faster apps faster?


At the end of this workshop, you'll know how to:

- Create Remix Routes

- Style Remix applications

- Load data in Remix loaders

- Mutate data with forms and actions

This workshop has been presented at React Summit 2022, check out the latest edition of this React Conference.

FAQ

Remix is a web development framework that focuses on improving the bridge between the client and server, effectively handling the hardest part of web development which is the network chasm. It leverages web standards for routing, data loading, and actions, allowing developers to build more with less while ensuring an optimized user experience.

While Remix is primarily designed for web applications, there is potential for compatibility with React Native, particularly in sharing components and possibly utilizing loaders. However, this integration is not officially supported yet and would require custom solutions or further development from the community or the Remix team.

Remix allows developers to associate individual CSS files with specific routes, enabling styles to be independent and not affect other parts of the application. This approach leverages the capabilities of the web platform, avoiding the cascade issues common in traditional CSS management. Remix supports traditional CSS, Tailwind CSS, and plans to improve support for CSS modules and Vanilla Extract.

Remix provides robust error handling mechanisms through error boundaries and catch boundaries, which can be used to render fallback UI components when data fetching or other operations fail. These boundaries ensure that errors are managed gracefully, providing a better user experience and maintaining application stability.

Remix automatically re-fetches all page data upon successful mutations, eliminating the need for manual state management related to data synchronization. This model simplifies development by reducing the complexity associated with keeping the UI and server state consistent. Developers can focus more on features rather than state management intricacies.

Integrating Remix with existing applications like those built with Next.js involves setting up a proxy, such as Express or Nginx, to route specific paths to Remix or the existing system. This approach allows for gradual migration and coexistence of both frameworks during the transition period.

The Remix team is exploring various monetization strategies including offering services around Remix similar to what Laravel does, building products akin to what Rails has with Basecamp, or potentially partnering with larger companies through acquisitions or collaborations.

Kent C. Dodds
Kent C. Dodds
136 min
04 Jul, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Remix simplifies state management and data loading in web applications, combining modern web development with the simplicity of managing state in the backend. It supports nested routing and provides a convenient way to associate parent and child components based on URL segments. Remix handles data fetching, mutations, and error states automatically. It offers flexibility in accessing loader data and allows for multiple instances of loader data in a component. Remix also provides seamless handling of form updates, error handling, and redirects.
Available in Español: Fundamentos de Remix

1. Introduction to Remix and Exercise 1

Short description:

Welcome everyone. We're going to talk about Remix and cover topics like nested routing, data loading, dynamic parameters, mutations, and progressive enhancement. In Exercise 1, we'll add a link to the post route in the Indy Stack. We'll go through the README and stop at loading data. Then, we'll create a post index route in our routes directory. TypeScript is recommended for building web applications with Remix, but it's not mandatory. Let's get started!

Welcome everyone. I am super excited to talk with you all about Remix. I think it's amazing and I think that we're all gonna have a great time learning about Remix. Let me get my screen prepared. And so this is the the workshop repo, and this is the workshop running locally. Let me bump that up just one here a little bit, scoot that over.

So here is our outline. We're gonna, we're not going to get through all of this stuff. We only have three hours, so we're going to work through some of this. I do want to give you some time with your hands on the keyboard, but because we're so limited on time I have a feeling that you're more interested in me or in getting through more content than spending as much time with your hands on the keyboard. That's my guess. That's the assumption I'm going to be operating under. So, because of that, I will give you a little bit of time on some of these as exercises, but most of the time you're gonna just be watching and asking questions and stuff in the Discord. And I think that will be the best use of the limited time that we have.

So we're going to talk today about nested routing, data loading, dynamic parameters, nested routing, mutations, progressive enhancement, and then there's homework, all sorts of things that we can do for the homework. Some of these things will just kind of breeze over and stuff. So I want to kind of give you an introduction to what Remix Even is and kind of the unique value proposition and everything. But I'd like to get things rolling quicker. And so I think we're going to do the first exercise and then we'll loop around and do a little is Remix Even. This is actually part of my strategy for learning. It's just kind of throwing you into the deep end. So we're going to start with Exercise 1 and you're not actually going to CD into this directory. So the way that this works is we have a special script called route runner. So this is called dev, that you can run, NodeDev and then you give it the path to the exercise that you want and it will run that exercise and what's cool about this is it will run it on a port that is associated to the exercise. So you could run all of the exercises and all of the finished versions of the exercises all at the exact and they will all work, which is kind of fun and fancy. So if you run NodeDev exercise zero one routing, and actually a quick tip, you can actually do just zero one and that will also work so you don't have to type the whole thing out, but then you pop open Locos 4001 and you're presented with this page that is the Indy stack. So Remix has this feature for project generation where you generate new projects and we call these stacks. It has a bunch of tools and stuff that come pre-installed and pre-configured for you. And the tutorial that we're going through is based on the Indy Stack. So that is where we're going to start is in exercise one with basically a pre-generated Indy Stack and your job for this exercise is simply to add a link right here, just below the big image here, to take you to the post route. We're going to add a blog to this site. So that's what we're going to do. That's your first exercise. You're going to go into exercise 01 routing, go to the README, and this will give you a starting place and a stopping place in the blog tutorial. So you'll start with your first route, and you will stop right when you get to loading data. So you won't continue through loading data, you'll just stop right here for this exercise. And so we're going to stick that in our routes index j.s. So this is our home page. That's where we want it to go. And we're just going to put it right there. It doesn't really matter where it is because we're not learning j.s.x. and proper structure or whatever. That doesn't really matter. So we're coming over here. We've got a link to blog post. And when I click on that link, we're going to get a four or four because even though we are actually going to that URL, we don't actually have anything there. And fun fact, because Remix is server rendered, you actually get a 404 from the server when going to that page, all the stuff that we've been doing on the client for the last six to eight years. When you have a route that is not not supported, you get the index HTML. So you get a 200. And the client just says, Oh, we can't find it. But Remix because of server rendered, can actually give a proper status code, which is really good for for SEO for the browser behaving the proper way all that stuff. So that's nice. But we want to have something there. And so in the next step here, we make a new route, and that is controlled by having a new route. And that is controlled by having a file at posts. And we want to have the index for our posts. So we'll create a post index route on in our routes directory. So let's make posts, and then index dot TSX. And Oh, by the way, I, I just assumed that we're all doing TypeScript. TypeScript is the way that you build web applications these days. And if you're not familiar with TypeScript, you'll be pleased to know that there's actually not a ton of TypeScript weirdness that you have to do with Remix. There's a little bit. But yeah, it is so so nice. So if you're not used to TypeScript, you can feel free to just leave the types off it will still work. You'll just get little red squiggles in some places. It's not a big deal. Okay, so we're just going to copy this because again, I don't think that you care to spend time writing jsx but the important thing here is that our module exports default, a function component. I guess it could be a class component. I don't know why I distinguished with function but you export a function or a component. And, and that is what's going to be rendered when the user lands on the post page.

2. Remix and React Router Integration

Short description:

So there it is posts. We have this link to the posts route and then the posts is a file under routes called, with a default export for what should be rendered when we're on that route. This would be with the convention that we currently have for Remix for the file structure, you can just have a posts.TSX. Remix uses React router remix came from the creators of React router. Remix is just using React router here. Remix is focused on web standards and modern web app UX. Remix takes the things that worked really well in the web 10 years ago, and then Remixes the things that work really well in the modern web. The thing that bothers people who have been involved in the web for a long time about the modern web is how hard it is to build a website these days. What Remix manages to do is, the thing that we liked about the older way of building websites is you didn't have to worry about managing state in the browser.

So there it is posts. And that that's everything that was the whole exercise was you literally just add a link using this link component that's coming from remix. And this is actually just being being re exported essentially from react router. There's a couple additional features but for the most part it's just being re exported. And in fact the additional features are being moved into React router proper.

So anyway, we have this link to the posts route and then the posts is a file under routes called, with a default export for what should be rendered when we're on that route. Could that posts folder just be a file post.TSX or does it have to be an index file? Great question. Yeah yeah. So we'll go ahead and do this now. This would be with the convention that we currently have for Remix for the file structure, you can just have a posts.TSX so we could put all this stuff in here instead and we'll get the same result and like, of course I could delete this or whatever but in the next couple of exercises, we're also going to have post slash slug with whatever the post name is and so we're going to need to have the post directory eventually. And so this is effectively the homepage for the post so the index page for the post and so that's what we just started with the index page. But it's not necessarily wrong to have this file because there could be like some sort of special nav or footer that you want for all your posts and that's what you would put in this. We'll talk about that a little bit more when we get into nested routing, doing the admin UI but just to give you a quick sample of what this is, this it would be the parent route of this index route and all the routes inside of this post directory and so parents need to say what where the children should be rendered and so the way that we do that is via the outlet component from remix run react. And so now I can say render my outlet and I'll wrap it in a div and say here's my footer stuff and my header stuff and then we come over here and I have my header stuff, the posts, this is the index route that's coming from our index right here, this right there and then our footer stuff. And so now every route inside of the post directory is gonna have the header stuff and wrapping whatever the child route is. And so that that absolutely is helpful and now this is controlling some of the layout for us. And then just saying where the the children should be rendered. But we don't really want to wrap anything. So we'll just do this and now what we're looking at is actually the default parent route. So if you don't have a parent route, this is the default basically is nothing. It's routing a structure that is something like React router six, which has outlet and it can some, put some routing inside them and have parents. Is it something like that?

Yes, that's exactly what it is. This remix uses React router remix came from the creators of React router. And so that's and React router is getting a lot of cool remix features very soon. Okay. Thank you. Yeah, in fact, fun fact, a couple months ago, is it months now maybe a couple weeks on our blog, we wrote this post called remixing React router, where we're taking a bunch of the really cool features from React router, and bringing them into, I'll just drop a link to that in the discord, bringing them into. or a bunch of the features from remix into React router. And actually, we could title this post differently, and instead say unreacting React router because we're basically taking all as we're taking all these features of remix and putting them into React router. We're just getting, we are kind of separating the core features of remix and React. And so what that's going to allow us to do is now React router is an adapter for remix router, and then we can make adapters for Vue and for Svelte and for angular and for preact and all of these things. So, the whole web is actually going to be able to take advantage of remix, regardless of what UI library you decide to use, which is pretty significant. So, the future version, and we have this on pre-release right now, we're thinking we may release this either this week or next week, where we'll have the remix router, and then just adapters for that router, which is cool. And community members are already building adapters for remix router, for Vue, Angular, Svelte and Preact. And, I think there may be another one, I can't remember which, but, so yeah, exciting times, and yes. So absolutely, remix is just using React router here.

I have a very basic question, maybe, like remix is running on the back end, not on the front end, like, if you would have a normal React application, it would run on the front end as a single page application, but remix is running on Node server or something, right?

Yes, yeah, but it is a SPA, a single page application when it hydrates, and so if you come over to your homepage, that was a, like, this is all server rendered, you look at the view source and you're seeing, like, all the HTML and everything in there, but when you navigate to blog posts, you're not getting a full page reload or anything, we're just loading in the JavaScript necessary for that page, and we'll do the same for the CSS and data and everything else as well. So, it is a client-side transition that's happening here, so you get like page transitions, focus management, all that stuff.

Now that we've done the first exercise, what I want to do is take a moment to talk about what is Remix, and this thing that you just toyed around with for a second, so Remix is focused on web standards and modern web app UX. You could say that we're remixing the old with the new, and so I'm going to, in Discord, I'm going to say raise your hand, raise your hand, here, I'll move this over so y'all can see what I'm doing. If you have been, or actually let's do how many years have you been in web dev. And so if you've been in for nine years, nine, there we go. If you've been in nine or more, oh whoops, that was supposed to be here. No stop chatting. We're just going to do emoji reactions. You're too fast. If you've been in nine or more, then do nine, otherwise do eight or seven or yeah, the number, you get it. So for me, I started web dev in officially 2014. So that gives me eight. So there we go, cool. So actually we've got quite a few of you who've been in for nine or more. Let's see. So for those of you who've been in for nine or more years, then you'll actually find this. Oh, there's a 10, oh man, I didn't know there was a 10. Whoops, yeah. You could do the 10 if you want to. So yeah, for those of you who have been in for a while, you'll find this to be very familiar and very comfortable because Remix takes the things that worked really well in the web 10 years ago, and then Remixes the things that work really well in the modern web in things these days. So the thing that bothers people who have been involved in the web for a long time about the modern web is how hard it is to build a website these days. There are so many things you have to do. You have your build tools, you have your linters and your formatters, and you've got your JSX, and you've got your JavaScript stuff. And now you've got to manage state in the UI and so many things that you have to do these days that you didn't have to do back then. And I would always convince myself and say, well, yeah, but our apps are way better than they used to be. We can do way more than we used to be able to do back then. And yes, that's true. The browser's way more capable. Good luck building Figma back in the late 90s or early thousands. Yeah, that's silly. So that's what I always convinced myself of. But what Remix manages to do is, the thing that we liked about the older way of building websites is you didn't have to worry about managing state in the browser. All state was basically just lived in the database and maybe you'd put a cache in somewhere in place to make things faster.

QnA