The Ultimate React Tutorial: From Beginner to Pro with RSCs, Next.js, Shadui, Drizzle, TS and More

Posted by


Welcome to the comprehensive guide on how to build a modern React application from scratch all the way to production! In this tutorial, we will cover advanced topics such as React State Components (RSCs), Next.js, Shadui for UI components, Drizzle for blockchain integration, TypeScript for type safety, and more. By the end of this tutorial, you will have a fully functional application ready for deployment.

Step 1: Getting Started

To begin, make sure you have Node.js and npm installed on your machine. You can check this by running node -v and npm -v in your terminal. If you don’t have them installed, you can download and install them from the Node.js website.

Next, create a new project directory and navigate into it. Run the following command to create a new React app using Create React App:

npx create-react-app my-app
cd my-app

Step 2: Setting up React State Components (RSCs)

React State Components (RSCs) are a new way to manage state in React applications. They provide a cleaner and more efficient way to handle state without the need for class components. To use RSCs in your project, you will first need to install the @hookstate/core package:

npm install @hookstate/core

Next, create a new file called AppContext.js in your src directory. In this file, you can define your RSCs and export them for use in your components. Here is an example of how you can define an RSC for managing a todo list:

import { State } from '@hookstate/core';

export const todoList = State([]);

To use the todoList RSC in your components, you can import it at the top of your file and then access its value and set functions. For example:

import { todoList } from './AppContext';

function TodoList() {
  const list = todoList.get();

  const addTodo = (text) => {
    todoList.set([...list, { text, done: false }]);
  };

  // Other functions to manipulate the todoList

  return (
    // JSX for rendering the todo list
  );
}

Step 3: Using Next.js for Server-side Rendering

Next.js is a popular framework for building React applications with server-side rendering capabilities. It provides better SEO performance and faster page loading times compared to traditional client-side rendering. To set up Next.js in your project, run the following commands:

npx create-next-app my-next-app
cd my-next-app

Next, install the next and react packages in your project:

npm install next react react-dom

You can now start your Next.js development server by running:

npm run dev

Step 4: Integrating Shadui for UI Components

Shadui is a UI component library built for React applications. It provides a collection of customizable and reusable components such as buttons, inputs, modals, and more. You can easily integrate Shadui into your project by installing the shadui package:

npm install shadui

In your components, you can import Shadui components and use them as needed. For example, to use a button component in your app:

import { Button } from 'shadui';

function MyComponent() {
  return (
    <Button onClick={() => console.log('Button clicked')}>Click me!</Button>
  );
}

Step 5: Adding Drizzle for Blockchain Integration

Drizzle is a library that allows you to easily integrate Ethereum blockchain functionality into your React applications. It provides a set of Redux-like tools for managing and interacting with smart contracts. To use Drizzle in your project, install the drizzle package:

npm install drizzle

You can then configure Drizzle to connect to your Ethereum network and load your smart contracts. For more information on using Drizzle, refer to the official documentation.

Step 6: Implementing TypeScript for Type Safety

TypeScript is a statically typed superset of JavaScript that adds type safety and other advanced features to your code. It can help catch bugs and improve code quality by providing compile-time checks on types. To add TypeScript to your project, run the following commands:

npm install typescript @types/node @types/react @types/react-dom

Next, rename your .js files to .tsx to indicate that they are TypeScript files. You can now add type annotations to your code and benefit from TypeScript’s type checking capabilities.

Step 7: Building and Deploying to Production

Once you have completed your application and are ready to deploy it to production, you can build your project using the following command:

npm run build

This will create an optimized production build of your React application. You can then deploy this build to a server using tools like Netlify, Vercel, or Firebase Hosting.

Congratulations! You have now successfully built a modern React application using RSCs, Next.js, Shadui, Drizzle, TypeScript, and more. I hope this tutorial has been helpful in guiding you through the process of building and deploying a production-ready React application. Happy coding!

0 0 votes
Article Rating
36 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@t3dotgg
1 month ago

UPDATES:
– create-t3-app now uses latest Next, which should fix some bugs with hot reloading on parallel routes
– MAKE SURE YOU USE THE DEFAULT PREFIX WHEN SETTING UP VERCEL POSTGRES
– Clerk Core 2 is no longer in beta! If you just `pnpm install @clerk/nextjs` you will have this version now 🙂

Oh also – GITHUB REPO IS HERE: https://github.com/t3dotgg/t3gallery

@bkschatzki
1 month ago

For those having an issue with it trying to getImage of the image you just deleted: check whether it only applies to parallel routes or also after hard navigating to that image. Ask yourself why that is. Search "next 14.2 parallel routes redirect workaround". The default.tsx just needs a page.tsx also returning a null. This has to do with how Next handles soft navigation. A few behaviors must have changed since this video was made, and the docs show a slightly different setup for the slot.

@xPorkchops007x
1 month ago

1:09:37 Phrasing

@mariotjimenez
1 month ago

@t3dotgg Hey theo, thanks for this! It was very well done. I wanted to ask if you are willing cover unit tests too in the future?

@jaafarskafi1
1 month ago

Thanks!

@kaizenza
1 month ago

Great video! Love it! Would love to see a video on how you manage DEV to PROD in Vercel and any lessons learned you have experienced.

@joblafors
1 month ago

Would be great if you could cover trpc with Clerk middleware as well.

@jamesauble8091
1 month ago

I'm not getting replay working out of the box. what gives?

@Shumaildev
1 month ago

Best tutorial ever seen 🥵

@CoenBijpost
1 month ago

You can create the backdrop by using backdrop: classnames from tailwind. You don’t even need a separate backdrop div. You can create blur, darkening, even sepia and other cool effects and it’s all styling ON the dialog element. Which is amazing, tbh…

@frezzingaces
1 month ago

I'm very confused what the `(.)` does in the route `@modal/(.)img/[id]/modal.tsx` in the parallel routes section. I get that parenthesis are for route groups, but I just don't get how it works in this case?

@branmuller
1 month ago

Of course now import { useRouter } from 'next/navigation' is a client side thing

@siarkonyar4042
1 month ago

which autocomplete extension do you use? does anyone else know a usefull extension for it??

@marcusradell7544
1 month ago

To reset the env vars in Vercel, go to storage->projects->[…] (context menu for your project)->Remove Project Connection.
Afterwards, just add the connection again with the default settings.

I also just added the DATABASE_URL variable on top with the value I got from POSTGRES_URL. I figured that I never want the provider to dictate my own code.

@stuart9908
1 month ago

Thanks for the great video. Can anyone provide resources regarding db:push vs. migrations? Im not familiar with this debate.

@matijafric9839
1 month ago

Is it possible to make uploadthing free tier to use some default region from EU for the EU users?

@jordan9506
1 month ago

They changed the Sentry global-error.tsx to be the default one and decided to use NextError

@Zefrem23
1 month ago

Me, a 20-year veteran of web development: "Daaaah… I know some of those words!"

@MrSprinkles1F369
1 month ago

Struggling to keep up. There is a lot of spontaneous deleting of half the code, then instantly repopulating it with copilot before I realised what happened.

@Try_it_
1 month ago

After I added the delete button code, I am getting an error when I click on the delete button in the modal only. Like when I click it in the modal, since the redirect function is called the url changes to the homepage but I get an error in the getImage function in queries.ts file that Image not found.
if (!image) throw new Error("Image not found")
What is the solution for it?