daanflore / carfac

Slides and example code on the training React Fundamentals, Carfac, November 2020

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

carfac

Slides and example code on the training React Fundamentals, Carfac, November 2020

Links - Day #1

Day #2

Day #3

Voorbeeld van een generieke service die de calls naar de API afhandelt (pseudo code):

import axios from 'axios'

// the API-URLs to get the data from
const url = 'https://restcountries.eu/rest/v2/all';
const detail_url = 'https://restcountries.eu/rest/v2/name';

export default new class CountryService{
	// 'lokale API' vor deze service
	getCountries(){
		return axios.get(url);

	}
	deleteCountry(country){
		//....
	}
	getSingleCountry(id){
		//....
	}
}

En in de component waar je dan de service wilt gebruiken, wordt deze geimporteerd:

import countryService from './services/CountryService'
...
componentDidMount(){
    countryService.getCountries()
        .then(response => {
            this.setState({
                isLoaded: true,
                countries: response.data
            })
        })
}

Bedankt voor jullie aanwezigheid en vragen tijdens de opleiding.

Veel succes met React in uw werk!

Peter.

About

Slides and example code on the training React Fundamentals, Carfac, November 2020

License:MIT License