Code Monkey home page Code Monkey logo

full-modern-react's Introduction

Full Modern React

About This Project

This project was bootstrapped with Create React App. (Read more about this app in the auto-generated README-react-app.md document.)

Node.js is required for local development.

Quickstart After Cloning

To view the entire completed project for development locally, you'll need to open two terminal windows for your Node.js environment. Run the following in your project root:

  1. npx json-server --watch data/db.json --port 8000
  2. npm run start

After running the second command, your browser should automatically open the application, e.g. http://localhost:3000/.

Open up a third, separate terminal for any development purposes; keep the first two Node instances running in the background while you work.

Getting Started with Setup

  1. Install node.js if necessary.
  2. Navigate to the directory where you want to create your project root.
  3. Run the Create React App, replacing "project-name" with your own project:
    1. npx create-react-app project-name

For simple projects, you can delete the following:

  1. src/App.test.js
  2. src/reportWebVitals.js
    1. Open src/index.js to delete import reportWebVitals from './reportWebVitals'; and reportWebVitals();.
  3. src/setupTests.js

Getting Started With Development (Step 1)

In your terminal, run npm run start to execute the script which starts React and allows you to view your project in the browser.

Spinning Up A Quick Backend (Step 16)

At Step 16, this project starts using dummy content to simulate fetching blog posts from a database:

  1. Create a directory & JSON file with the blog content: data/db.json

  2. In the root project directory, run: npx json-server --watch data/db.json --port 8000

This starts a server which points to your database which you can query as a url/endpoint within your code. Changing the port is necessary because the server will default to port 3000, which is already in use by React.
Note: you may need to re-run npm run start after starting the json server.

Endpoints & HTTP Request Methods

  • /blogs

    • GET - Fetch all blogs
    • POST - Add a new blog
  • /blogs/{id}

    • GET - Fetch a single blog
    • DELETE - Delete a blog

Testing For Fetch Errors (Step 19)

Step 19 is all about error handling for network problems or URL/endpoint (resource) issues.

Network Error Testing

  1. Disconnect from json-server: ctrl+C
  2. Refresh the page in your browser. Any connection errors will be captured by the catch block and can be logged to the console.
  3. Reconnect to json-server after testing: npx json-server --watch data/db.json --port 8000

Resource Error Testing

  1. In the fetch block, change the URL to something nonexistent, e.g. "http://localhost:8000/blogs%%%%%".
  2. Refresh the page in your browser. Anything other than a successful delivery of the desired resource from the server will throw an Error("message") to the catch block.
  3. Reset the URL after testing, e.g. http://localhost:8000/blogs

React Router (Step 21)

Step 21 requires installation of a new dependency, the React Router. In a new terminal, run npm install react-router-dom@5. Once installed, view the package.json file to see the "react-router-dom..." listed under dependencies.

full-modern-react's People

Contributors

nvsmith avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.