Skip to content

jiheon788/react-query-realworld

Repository files navigation

logo-002

RealWorld Frontend

React + React Query codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

DemoΒ Β Β Β RealWorld

This codebase was created to demonstrate a fully fledged fullstack application built with React + React Query including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the TanStack Query community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

src
β”œβ”€ App.tsx
β”œβ”€ index.tsx
β”œβ”€ react-app-env.d.ts
β”œβ”€ Router.tsx # dynamic router assignment
β”œβ”€ components # components
β”œβ”€ constants # constants
β”œβ”€ contexts # context API
β”œβ”€ lib
β”‚  β”œβ”€ routerMeta.ts # meta data of router
β”‚  β”œβ”€ token.ts # localstorage class
β”‚  β”œβ”€ utils # utility funcs
β”‚  └─ hooks # custom hooks
β”œβ”€ pages # page components
β”œβ”€ queries # react query func
└─ repositories # api service
    └─ apiClient.ts # Axios Instance & Interceptor

Making requests to the backend API

For convenience, we have a live API server running at https://conduit.productionready.io/api for the application to make requests against. You can view the API spec here which contains all routes & responses for the server.

The source code for the backend server (available for Node, Rails and Django) can be found in the main RealWorld repo.

Using Marked Up Templates

You can check the marked up frontend spec here.

Getting Started

Install

npm i

Build

npm run build

Start

npm start

Functionality overview

The example application is a social blogging site (i.e. a Medium.com clone) called "Conduit". It uses a custom API for all requests, including authentication. You can view a live demo over at https://react-query-realworld.netlify.app

General functionality:

  • Authenticate users via JWT (login/signup pages + logout button on settings page)
  • CRU- users (sign up & settings page - no deleting required)
  • CRUD Articles
  • CR-D Comments on articles (no updating required)
  • GET and display paginated lists of articles
  • Favorite articles
  • Follow other users

The general page breakdown looks like this:

  • Home page (URL: /#/ )
    • List of tags
    • List of articles pulled from either Feed, Global, or by Tag
    • Pagination for list of articles
  • Sign in/Sign up pages (URL: /#/login, /#/register )
    • Uses JWT (store the token in localStorage)
    • Authentication can be easily switched to session/cookie based
  • Settings page (URL: /#/settings )
    • Editor page to create/edit articles (URL: /#/editor, /#/editor/article-slug-here )
  • Article page (URL: /#/article/article-slug-here )
    • Delete article button (only shown to article's author)
    • Render markdown from server client side
    • Comments section at bottom of page
    • Delete comment button (only shown to comment's author)
  • Profile page (URL: /#/profile/:username, /#/profile/:username/favorites )
    • Show basic user info
    • List of articles populated from author's created articles or author's favorited articles

Brought to you by Thinkster