Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.