A hands-on learning repository for React patterns, best practices, and common challenges. Practice component composition, state management, performance optimization, and more through guided exercises.
The exercises in this project are designed to be completed using React and TypeScript. You'll be most productive if you already have a basic understanding of React and its core concepts. Please refer to the official React documentation if you're new to React. Their tutorial is a great place to start.
Make sure you have Node.js and yarn installed:
- Node.js (v18+ recommended)
- Yarn Classic (v1.22.22)
# Clone repository
git clone https://github.com/yourusername/react-patterns-playground.git
cd react-patterns-playground
# Install dependencies
yarn install
# Create your first attempt
yarn create-attempt
# Select an exercise
yarn select-exercise
# Start development server
yarn dev
# Reset your attempts
yarn reset-attempts
- Run
yarn create-attempt. Previous attempts are preserved for reference. - Run
yarn select-exercise - Choose exercise from the menu
- Start development server with
yarn dev - Open browser at http://localhost:5173
- Navigate to the exercise directory in
src/attempts/your-latest-attempt/exercise-name/and review the instructions in theREADME.mdfile - Edit the
problem.tsxfile insrc/attempts/your-latest-attempt/exercise-name/
If you wish to reset your attempts, run yarn reset-attempts.
If you wish to see the solution, add /solution to the URL (e.g. http://localhost:5173/solution).
DO NOT modify the files in the exercise directory. These are the templates for new attempts.
- Avoiding Premature Abstraction
- Component Breakdown
- Hoisting State to the URL
- Refactoring a Nested Component
- Recursive Components
- Semantic HTML
- State Synchronization with useEffect
src/
├── exercises/ # Exercise templates
└── attempts/ # Your practice attempts
scripts/
├── create-attempt.ts # Creates new attempt directory
├── reset-attempts.ts # Resets all attempts
└── select-exercise.ts # Exercise selection utility
yarn dev: Start development serveryarn build: Build for productionyarn create-attempt: Create new practice attemptyarn reset-attempts: Reset all practice attemptsyarn select-exercise: Choose exercise to work onyarn format: Format code with Prettieryarn lint: Run ESLint
For development only:
yarn select-exercise:dev: Choose exercise to display when updating or adding an exercise
If you'd like to contribute new exercises:
- Create new directory in
src/exercises/ - Include:
problem.tsx: Exercise starter codesolution.tsx: Example solutionREADME.md: Exercise instructions
- Add exercise to
exercisesarray inexercises/index.ts - Run
yarn select-exercise:devand select the new exercise to ensure it displays in the development server
MIT