Top Related Projects
Documentation and Samples for the Official HN API
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
HNPWA - Hacker News readers as Progressive Web Apps 📱
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Exemplary real world application built with React + Redux
Quick Overview
React-hn is a React-based implementation of Hacker News, providing a modern and responsive interface for browsing the popular tech news aggregator. It offers a fast and efficient way to access Hacker News content with a clean, user-friendly design.
Pros
- Improved user experience with a responsive, React-based interface
- Fast loading times and efficient data handling
- Customizable and extensible codebase for developers
- Faithful representation of Hacker News content and functionality
Cons
- May require more resources than the original Hacker News site
- Potential for divergence from official Hacker News updates
- Limited to web browsers, unlike native mobile apps
- Dependency on external APIs and services
Code Examples
- Fetching stories from the Hacker News API:
import { fetchItems } from './api'
const fetchStories = async (ids) => {
const stories = await fetchItems(ids)
return stories.filter(story => story !== null)
}
- Rendering a story component:
const Story = ({ story }) => (
<div className="story">
<h2><a href={story.url}>{story.title}</a></h2>
<p>{story.score} points by {story.by}</p>
<p>{story.descendants} comments</p>
</div>
)
- Implementing infinite scrolling:
import { useInfiniteScroll } from './hooks'
const StoryList = () => {
const [stories, loadMoreStories] = useInfiniteScroll()
return (
<div>
{stories.map(story => <Story key={story.id} story={story} />)}
<button onClick={loadMoreStories}>Load More</button>
</div>
)
}
Getting Started
To get started with react-hn:
-
Clone the repository:
git clone https://github.com/insin/react-hn.git
-
Install dependencies:
cd react-hn npm install
-
Start the development server:
npm start
-
Open your browser and navigate to
http://localhost:3000
to view the app.
Competitor Comparisons
Documentation and Samples for the Official HN API
Pros of HackerNews API
- Official API provided by Hacker News, ensuring reliability and up-to-date data
- Comprehensive documentation with detailed endpoints and usage instructions
- Supports real-time updates through Firebase integration
Cons of HackerNews API
- Requires additional implementation to create a full-fledged web application
- Limited to raw data retrieval, lacking built-in UI components or rendering
Code Comparison
react-hn (React component):
const Story = ({ story }) => (
<div className="story">
<h2>{story.title}</h2>
<p>By {story.by} | {story.score} points</p>
<a href={story.url}>Read more</a>
</div>
);
HackerNews API (API request):
fetch('https://hacker-news.firebaseio.com/v0/item/8863.json')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Summary
react-hn is a React-based Hacker News client that provides a ready-to-use interface for displaying Hacker News content. It offers a complete solution with UI components and data fetching logic.
HackerNews API, on the other hand, is the official API that provides raw data access to Hacker News content. It requires additional development to create a user interface but offers more flexibility in terms of data usage and integration with various platforms.
The choice between the two depends on the specific needs of the project, with react-hn being more suitable for quick React-based implementations and HackerNews API offering more control and versatility for custom solutions.
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
Pros of vue-hackernews-2.0
- Utilizes Vue.js 3, offering improved performance and composition API
- Implements server-side rendering (SSR) for better SEO and initial load times
- Includes HMR (Hot Module Replacement) for a smoother development experience
Cons of vue-hackernews-2.0
- More complex setup and configuration due to SSR implementation
- Larger bundle size compared to react-hn due to additional features
Code Comparison
vue-hackernews-2.0:
<template>
<div class="news-view">
<news-list :type="type" />
</div>
</template>
<script>
export default {
name: 'NewsView',
props: ['type']
}
</script>
react-hn:
class NewsItem extends React.Component {
render() {
return (
<div className="NewsItem">
<div className="NewsItem__title">{this.props.item.title}</div>
</div>
)
}
}
The vue-hackernews-2.0 example showcases Vue's template syntax and component structure, while react-hn demonstrates React's class-based component approach. Vue's template-based structure may be more intuitive for some developers, while React's JSX offers more flexibility in rendering logic.
HNPWA - Hacker News readers as Progressive Web Apps 📱
Pros of hacker-news-pwas
- Multiple implementations showcasing different frameworks and approaches
- Comprehensive documentation and performance comparisons
- Focuses on Progressive Web App (PWA) features and best practices
Cons of hacker-news-pwas
- Less focused on a single, polished implementation
- May be overwhelming for beginners due to multiple versions
- Potentially more complex to maintain and update across all implementations
Code Comparison
react-hn:
class Item extends Component {
render() {
const { item } = this.props
return (
<div className="Item">
<div className="Item__title">{item.title}</div>
<div className="Item__meta">{item.by} | {item.time}</div>
</div>
)
}
}
hacker-news-pwas (React version):
const Story = ({ story }) => (
<article>
<h2 className="title">
<a href={story.url}>{story.title}</a>
</h2>
<div className="meta">
{story.score} points by {story.by} | {story.descendants} comments
</div>
</article>
)
Both repositories aim to create Hacker News clients, but hacker-news-pwas offers a broader range of implementations and focuses on PWA features. react-hn provides a more focused, single-implementation approach. The code comparison shows similar component structures, with hacker-news-pwas using a functional component and react-hn using a class component.
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Pros of hackernews-react-graphql
- Utilizes GraphQL for efficient data fetching and management
- Implements server-side rendering for improved performance and SEO
- Includes TypeScript support for enhanced type safety and developer experience
Cons of hackernews-react-graphql
- More complex setup and learning curve due to additional technologies (GraphQL, SSR)
- Potentially higher initial development time compared to simpler React-only solutions
- May be overkill for smaller projects or those not requiring advanced features
Code Comparison
react-hn:
const Story = ({ story }) => (
<div className="Story">
<div className="Story_title">{story.title}</div>
<div className="Story_meta">{story.score} points by {story.by}</div>
</div>
);
hackernews-react-graphql:
const Story: React.FC<StoryProps> = ({ story }) => (
<div className="story">
<h2>{story.title}</h2>
<p>{story.score} points by {story.by}</p>
{story.url && <a href={story.url}>Read more</a>}
</div>
);
Both repositories aim to create a Hacker News clone using React, but hackernews-react-graphql offers a more modern and feature-rich approach with GraphQL integration and server-side rendering. While it provides additional benefits, it also comes with increased complexity. The choice between the two depends on project requirements and developer preferences.
Exemplary real world application built with React + Redux
Pros of react-redux-realworld-example-app
- More comprehensive and feature-rich, showcasing a full-fledged application
- Utilizes Redux for state management, demonstrating best practices
- Includes user authentication and CRUD operations
Cons of react-redux-realworld-example-app
- More complex codebase, potentially harder for beginners to grasp
- Larger bundle size due to additional dependencies
- May be overkill for simpler applications or learning purposes
Code Comparison
react-redux-realworld-example-app:
import { createStore, applyMiddleware } from 'redux';
import { createLogger } from 'redux-logger';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import { promiseMiddleware, localStorageMiddleware } from './middleware';
import reducer from './reducer';
react-hn:
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import App from './App';
The code comparison shows that react-redux-realworld-example-app uses Redux with middleware and dev tools, while react-hn has a simpler setup focused on React and routing. This reflects the difference in complexity and feature set between the two projects.
react-redux-realworld-example-app is better suited for developers looking to learn advanced React patterns and Redux integration, while react-hn might be more appropriate for those seeking a lightweight, focused implementation of a news aggregator.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
react-hn
A React & react-router-powered implementation of Hacker News using its Firebase API.
Live version: https://insin.github.io/react-hn
Features
- Supports display of all item types: stories, jobs, polls and comments
- Basic user profiles
- Collapsible comment threads, with child counts
- "Realtime" updates (free via Firebase!)
- Last visit details for stories are cached in
localStorage
- New comments are highlighted:
- Comments since your last visit to an item
- New comments which load while you're reading an item
- New comments in collapsed threads
- Automatic or manual collapsing of comment threads which don't contain any new comments
- Manual highlighting of the X most recent comments to catch up on threads you were reading elsewhere
- Stories with new comments are marked on list pages
- Stories can be marked as read to remove highighting from new comments
- "comments" sections driven by the Changed Items API
- Story listing pages are cached in
sessionStorage
for quick back button usage and pagination in the same session - Configurable settings:
- auto collapse - automatically collapse comment threads without new comments on page load
- show reply links - show "reply" links to Hacker News
- show dead - show items flagged as dead
- show deleted - show comments flagged as deleted in threads
- Delayed comment detection - so tense! Who will it be? What will they say?
Building
Install dependencies:
npm install
npm scripts
npm start
- start development servernpm run build
- build into thedist/
directorynpm run lint
- lintsrc/
npm run lint:fix
- lintsrc/
and auto-fix issues where possible
MIT Licensed
Top Related Projects
Documentation and Samples for the Official HN API
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
HNPWA - Hacker News readers as Progressive Web Apps 📱
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Exemplary real world application built with React + Redux
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot