From f555e42669e1925143e4a4d99b7e95d335b1f46b Mon Sep 17 00:00:00 2001 From: ardaninsaturnu Date: Mon, 6 Jun 2022 20:54:20 +0300 Subject: [PATCH] all feature done. --- .../src/index.js | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/14_Day_Component_Life_Cycles/14_component_life_cycles_boilerplate/src/index.js b/14_Day_Component_Life_Cycles/14_component_life_cycles_boilerplate/src/index.js index b9f802e..74cf6e2 100644 --- a/14_Day_Component_Life_Cycles/14_component_life_cycles_boilerplate/src/index.js +++ b/14_Day_Component_Life_Cycles/14_component_life_cycles_boilerplate/src/index.js @@ -15,49 +15,49 @@ class App extends Component { console.log('I am componentDidMount and I will be last to run.') const API_URL = 'https://restcountries.eu/rest/v2/all' fetch(API_URL) - .then((response) => { - return response.json() - }) - .then((data) => { - console.log(data) - this.setState({ - data, + .then((response) => { + return response.json() + }) + .then((data) => { + console.log(data) + this.setState({ + data, + }) + }) + .catch((error) => { + console.log(error) }) - }) - .catch((error) => { - console.log(error) - }) } renderCountries = () => { return this.state.data.map((country) => { return ( -
-
- {' '} - {country.name}{' '} -
-

{country.name}

-

Population: {country.population}

+
+ {' '} + {country.name}{' '} +
+
+

{country.name}

+

Population: {country.population}

+
-
) }) } render() { return ( -
-

React Component Life Cycle

-

Calling API

-
-

There are {this.state.data.length} countries in the api

-
{this.renderCountries()}
+
+

React Component Life Cycle

+

Calling API

+
+

There are {this.state.data.length} countries in the api

+
{this.renderCountries()}
+
-
) } } const rootElement = document.getElementById('root') -ReactDOM.render(, rootElement) +ReactDOM.render(, rootElement) \ No newline at end of file