Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
},
"devDependencies": {}
}
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_KEY = <enter API key>
6 changes: 5 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import Titles from "./components/Titles";
import Form from "./components/Form";
import Weather from "./components/Weather";

const API_KEY = "3585775f387b0d0cba6c5b3dc41b8167";
// You can add an API key for production and replace null
const API_KEY = process.env.NODE_ENV === 'development' ? process.env.REACT_APP_API_KEY : null;

console.log(process.env);

class App extends React.Component {
state = {
Expand All @@ -21,6 +24,7 @@ class App extends React.Component {
const country = e.target.elements.country.value;
const api_call = await fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city},${country}&appid=${API_KEY}&units=metric`);
const data = await api_call.json();

if (city && country) {
this.setState({
temperature: data.main.temp,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from "react";

const Form = props => (
<form onSubmit={props.getWeather}>
<input type="text" name="city" placeholder="City..."/>
<input type="text" name="country" placeholder="Country..."/>
<input type="text" name="city" placeholder="City"/>
<input type="text" name="country" placeholder="Country e.g. 'USA'"/>
<button>Get Weather</button>
</form>
);
Expand Down