This project is a clone of the Hacker News website built using React, TypeScript, Vite, Zustand for state management, and TailwindCSS for styling. The app fetches stories from the Hacker News API and includes infinite scrolling and real-time updates.
- Features
- Technologies
- Project Structure
- Installation
- Usage
- State Management
- Styling
- Contributing
- License
- Fetches Hacker News stories via API
- Infinite scrolling with auto-pagination
- Zustand for global state management
- TailwindCSS for responsive design
- Built with React + TypeScript and Vite for fast builds
- ESLint and Prettier configured for code consistency
- React 18.3 - Core frontend library
- TypeScript - Static type-checking
- Vite - Fast build tool and dev server
- Zustand - Lightweight state management
- TailwindCSS - Utility-first CSS framework
- Hacker News API - Data source for stories
- ESLint - Code linting
- Prettier - Code formatting
root/
│
├── public/ # Public assets
├── src/
│ ├── components/ # React components
│ ├── hooks/ # Custom React hooks
│ ├── pages/ # Page components (Home, Story, etc.)
│ ├── store/ # Zustand store files
│ ├── App.tsx # Main application component
│ ├── index.scss # Global SCSS styles
│ ├── main.tsx # Entry point of the app
│ └── vite-env.d.ts # Vite environment types
│
├── package.json # Project configuration and dependencies
├── postcss.config.js # PostCSS configuration for TailwindCSS
├── tailwind.config.js # TailwindCSS configuration
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Vite configuration
└── README.md # Documentation
-
Clone the repository:
git clone https://github.com/pooyagolchian/hackernews-react.git cd hackernews-react
-
Install dependencies:
pnpm install
-
Start the development server:
pnpm dev
-
Build for production:
pnpm build
- Open your browser and go to
http://localhost:5173
to see the app in action. - Infinite scrolling will automatically load more stories as you scroll down.
State is managed using Zustand. The store handles pagination and story fetching from the Hacker News API.
import create from 'zustand';
const useStore = create((set) => ({
stories: [],
page: 1,
fetchStories: async () => {
const response = await fetch(`https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty&page=${page}`);
set((state) => ({ stories: [...state.stories, ...response.data] }));
},
}));
export default useStore;
TailwindCSS is used for styling, making the app responsive and ensuring a clean design without needing to write custom CSS. The global SCSS file handles a few overrides and additional custom styles.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.