Lee Zhao Yi Charles - Weather App Bootcamp#49
Lee Zhao Yi Charles - Weather App Bootcamp#49charlesleezhaoyi wants to merge 2 commits intorocketacademy:mainfrom
Conversation
Efficiency, depends on what you mean exactly. However, for your assumption below the code I am not sure if you are correct there. Did you try console logging? If you compare with the first api call, the second one follows the same pattern. You return the result of the axios api call, and then have access to the response. If you would use the fetch API instead of axios you might have to deal with promises however. That is my asumption here. |
| @@ -0,0 +1 @@ | |||
| REACT_APP_API_KEY = "7b21cfd53f18535e1e40070e76eec614" No newline at end of file | |||
There was a problem hiding this comment.
never ever commit your .env file. Always add the .env into the .gitignore file first before doing anything else. Check with git status if your .env is included in the changes before committing anything. If it is included, you set up your gitignore wrongly
| yarn-error.log* | ||
|
|
||
| # environment variables | ||
| ./env No newline at end of file |
There was a problem hiding this comment.
| ./env | |
| .env |
the slash here will assume a directory called env but it is a single file in the root folder
|
|
||
| handleSubmit = (event) => { | ||
| event.preventDefault(); | ||
| const APIKey = process.env.REACT_APP_API_KEY; |
There was a problem hiding this comment.
I would place this outside of the component, so it is always available and not has to be looked up on every form submission.
| Edit <code>src/App.js</code> and save to reload. | ||
| </p> | ||
| <h2>Weather Forecast</h2> | ||
| {error !== "" ? error : ""} <br /> |
There was a problem hiding this comment.
| {error !== "" ? error : ""} <br /> | |
| {error && error} <br /> |
| {error !== "" ? error : ""} <br /> | ||
| {/* Display error message */} | ||
| Description: {weather_description} <br /> | ||
| Temperature: {temperature === "" ? "" : temperature + " Celsius"}{" "} |
There was a problem hiding this comment.
| Temperature: {temperature === "" ? "" : temperature + " Celsius"}{" "} | |
| Temperature: {!temperature ? "" : temperature + " Celsius"} |
| Description: {weather_description} <br /> | ||
| Temperature: {temperature === "" ? "" : temperature + " Celsius"}{" "} | ||
| <br /> | ||
| Humidity: {humidity === "" ? "" : humidity + "%"} |
There was a problem hiding this comment.
| Humidity: {humidity === "" ? "" : humidity + "%"} | |
| Humidity: {!humidity ? "" : humidity + "%"} |
| value={city} | ||
| onChange={(e) => this.setState({ city: e.target.value })} | ||
| ></input> | ||
| <button onClick={(event) => this.handleSubmit(event)}> |
There was a problem hiding this comment.
| <button onClick={(event) => this.handleSubmit(event)}> | |
| <button onClick={this.handleSubmit}> |
the function in the onClick will always have the event as argument. So if you directly pass handleSubmit as reference, the event argument is still valid
Questions:
In the code block above from Rocket's documentation, I tried the code but I think we only receive the promise but not the data in the second .then block. Not sure if my understanding is accurate/correct.