Skip to main content
React 18 with Vite provides a fast, lightweight development experience for building modern single-page applications.

Overview

React 18 is perfect for simple client-side applications, learning projects, and SPAs that don’t require server-side rendering.

Pre-installed Packages

  • React 18: Latest React library with concurrent features
  • Vite: Next-generation frontend tooling with fast HMR
  • Chakra UI: Accessible component library with built-in theming
  • Tailwind CSS: Utility-first CSS framework
  • TypeScript: Full type safety
  • Lucide React: Icon library

Key Features

  • Fast HMR (Hot Module Replacement) with Vite
  • Concurrent rendering features
  • Automatic batching
  • Suspense support
  • Chakra UI’s accessible components
  • Built-in dark mode support

Use Cases

React 18 is best suited for:

Simple SPAs

Client-side single-page applications without SSR requirements

Learning Projects

Educational projects and React practice applications

Prototypes

Quick prototypes and proof-of-concept applications

Interactive Tools

Calculators, converters, and client-side utilities

Chakra UI Components

Chakra UI provides accessible, composable components with built-in styling props and theming support.

Available Components

  • Layout: Box, Container, Flex, Grid, Stack, Wrap
  • Forms: Button, Input, Select, Checkbox, Radio, Switch, Textarea
  • Data Display: Badge, Card, Code, Divider, Kbd, List, Stat, Table, Tag
  • Feedback: Alert, Progress, Skeleton, Spinner, Toast
  • Navigation: Breadcrumb, Link, Menu, Tabs
  • Overlay: Drawer, Modal, Popover, Tooltip

Component Usage

import { Button, Stack } from '@chakra-ui/react';

export const App = () => {
  return (
    <Stack spacing={4} direction='row'>
      <Button colorScheme='blue'>Primary</Button>
      <Button colorScheme='red'>Danger</Button>
      <Button variant='outline'>Outline</Button>
      <Button variant='ghost'>Ghost</Button>
      <Button isLoading>Loading</Button>
    </Stack>
  );
};

Critical Rules

Main File: The entry point is src/App.tsx. Do not modify src/main.tsx.
Pre-installed: Chakra UI is already installed. Do not run installation commands for Chakra UI or Tailwind CSS.

File Conventions

  • Main file: src/App.tsx
  • Entry point: src/main.tsx (do not modify)
  • Component files: ComponentName.tsx (PascalCase)
  • Hook files: useHookName.ts (camelCase with ‘use’ prefix)
  • Components directory: src/components/
  • Hooks directory: src/hooks/
  • Utils directory: src/utils/
  • Types directory: src/types/

Component Structure

import React from 'react';

interface ComponentNameProps {
  title: string;
  onAction?: () => void;
}

export const ComponentName: React.FC<ComponentNameProps> = ({ title, onAction }) => {
  // Component logic
  
  return (
    <div>
      {/* JSX */}
    </div>
  );
};

Project Structure

src/
├── App.tsx               # Main application component
├── main.tsx              # Entry point (do not modify)
├── components/           # React components
├── hooks/                # Custom hooks
├── utils/                # Utility functions
└── types/                # TypeScript type definitions

Chakra UI Styling Props

Chakra UI components accept styling props for quick customization:
import { Box, Flex } from '@chakra-ui/react';

export const App = () => {
  return (
    <Box
      p={4}              // padding
      m={2}              // margin
      bg='blue.500'      // background
      color='white'      // text color
      borderRadius='md'  // border radius
      boxShadow='lg'     // box shadow
    >
      <Flex
        direction='column'
        align='center'
        justify='space-between'
        gap={4}
      >
        Content here
      </Flex>
    </Box>
  );
};

React Hooks

import { useState } from 'react';
import { Button, Text, VStack } from '@chakra-ui/react';

export const App = () => {
  const [count, setCount] = useState(0);

  return (
    <VStack>
      <Text>Count: {count}</Text>
      <Button onClick={() => setCount(count + 1)}>
        Increment
      </Button>
    </VStack>
  );
};

Styling with Tailwind

Combine Chakra UI with Tailwind utilities:
import { Card, CardHeader, CardBody } from '@chakra-ui/react';

export const App = () => {
  return (
    <Card className='max-w-md mx-auto mt-8'>
      <CardHeader className='bg-gradient-to-r from-blue-500 to-purple-600'>
        <h2 className='text-white text-xl font-bold'>Gradient Header</h2>
      </CardHeader>
      <CardBody className='p-6'>
        <p className='text-gray-700'>Custom styled card</p>
      </CardBody>
    </Card>
  );
};

Best Practices

// Prefer this
export const Component: React.FC = () => {
  const [state, setState] = useState();
  return <div />;
};

// Avoid class components
// src/hooks/useFetch.ts
export function useFetch(url: string) {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);
  
  useEffect(() => {
    fetch(url).then(r => r.json()).then(setData).finally(() => setLoading(false));
  }, [url]);
  
  return { data, loading };
}
{items.map((item) => (
  <div key={item.id}>{item.name}</div>
))}
import { Component, ErrorInfo, ReactNode } from 'react';

class ErrorBoundary extends Component<{children: ReactNode}> {
  componentDidCatch(error: Error, errorInfo: ErrorInfo) {
    console.error(error, errorInfo);
  }
  
  render() {
    return this.props.children;
  }
}
import { useToast, Button } from '@chakra-ui/react';

export const App = () => {
  const toast = useToast();
  
  return (
    <Button onClick={() => toast({
      title: 'Success',
      status: 'success',
      duration: 3000,
    })}>
      Show Toast
    </Button>
  );
};

Getting Started

Framework Overview

Examples

API Reference

Build docs developers (and LLMs) love