mpolinowski / react-typescript

Why is Typescript always yelling at me... And how can I make it stop.

Home Page:https://mpolinowski.github.io/docs/Development/Javascript/2023-12-14-reactjs-typescript-2023/2023-12-14

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Typescript UI

Vite.js

Scaffold your React Typescript app with Vite.js:

npm create vite@latest react-ts --template react-swc-ts

Alternatives: Vanilla javascript and Typescript SSR:

npm create vite@latest react-js --template react-swc

npm create vite@latest react-ts-ssr
✔ Select a template: › ssr-react
✔ Select a variant: › TypeScript + SWC

Routing and State Management

React-Router and React-Redux:

npm install react-router-dom @reduxjs/toolkit react-hook-form react-redux

Frontend Components and Styling

ShadCN UI and Tailwind CSS

npm install -D tailwindcss postcss autoprefixer

tsconfig.json

{
  "compilerOptions": {
    // ...
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
    // ...
  }
}
npm i -D @types/node

vite.config.ts

import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
})
npx shadcn-ui@latest init

✔ Would you like to use TypeScript (recommended)? … yes
✔ Which style would you like to use? › New York
✔ Which color would you like to use as base color? › Zinc
✔ Where is your global CSS file? … src/styles/global.css
✔ Would you like to use CSS variables for colors? … yes
✔ Are you using a custom tailwind prefix eg. tw-? (Leave blank if not) …
✔ Where is your tailwind.config.js located? … tailwind.config.js
✔ Configure the import alias for components: … @/components
✔ Configure the import alias for utils: … @/lib/utils
✔ Are you using React Server Components? … no
✔ Write configuration to components.json. Proceed? … yes
npx shadcn-ui@latest add <component name>
import { Component } from "@/components/ui/<component name>"

Vite.js React Typescript SSR

Features

Mocked Backend Login

Login using Redux state to block access to components based on auth level:

React Typescript UI

HLS Live Streaming

Using hls.js to access *.m3u8 video streams:

React Typescript UI

React Typescript UI

JSON Rest APIs

Retrieving and displaying structured data from HTTP APIs:

React Typescript UI

React Typescript UI

Implement a search function by filtering the JSON data:

React Typescript UI

Dark/Light Theme

Using shadcn-ui to implement a day/night theme toggle:

React Typescript UI

Form Validation

Using react-hook-form for form validation:

React Typescript UI

Displaying Video Files

Play MP4 h.264 video files using video.js:

React Typescript UI

About

Why is Typescript always yelling at me... And how can I make it stop.

https://mpolinowski.github.io/docs/Development/Javascript/2023-12-14-reactjs-typescript-2023/2023-12-14


Languages

Language:TypeScript 83.1%Language:JavaScript 11.4%Language:CSS 4.5%Language:HTML 0.9%