Skip to content

daanflore/carfac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors