Skip to content

Instantly share code, notes, and snippets.

@sebastianczech
Last active December 12, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianczech/9ff52163be4894e6b126a6a4f6669c2a to your computer and use it in GitHub Desktop.
Save sebastianczech/9ff52163be4894e6b126a6a4f6669c2a to your computer and use it in GitHub Desktop.
React.js - create first app

About

Commands and code used to create my first React app during training.

Repositories

  1. Create React App - source coude and tool usefull for creating app in React.js
  2. Artur Chyży repository
  3. Pragmatists TDD Todos React app

Create React App

npm install -g create-react-app
create-react-app my-app
cd my-app/
npm start

Setup

Setup tests

npm install --save-dev enzyme enzyme-adapter-react-16 react-test-renderer jest-cli jest-enzyme

Install type definitions for npm

npm i @types/jest @types/enzyme @types/expect

JSON server for tests

Fake Online REST API for Testing and Prototyping: JSONPlaceholder

npm install -g json-server
json-server http://jsonplaceholder.typicode.com/db --port 3001

HTTP client

npm install --save axios

Przykład pobrania danych:

axios.get('http://localhost:3001/todos')
            .then(response => response.data)
            .then(data => {
                this.setState({
                    todos: data
                });
            })
            .catch();

Przykład dodania danych do serwera:

axios.post('http://localhost:3001/todos', todo)
            .then(() => this.fetchData());

Routing

npm install --save react-router react-router-dom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment