Promise homework - Stephanie's solution - #7
Open
stephanie56 wants to merge 11 commits into
Open
Conversation
- add api keys to config file - try to fetch data from edamam
- Update search behaviour: empty search term after successful fetch - Add search bar styles
hilaryhacksel
approved these changes
Feb 27, 2018
| import { RecipeList } from './components/RecipeList'; | ||
| import { SearchBar } from './components/SearchBar'; | ||
|
|
||
| import { APP_ID, APP_KEY } from './config/'; |
There was a problem hiding this comment.
nice job, moving keys into a new file
| import { APP_ID, APP_KEY } from './config/'; | ||
|
|
||
| const ErrorMessage = ({message, isLoading}) => { | ||
| return ( |
There was a problem hiding this comment.
I like to write my functions without returns if I can get away with it, like here!
| } | ||
|
|
||
| fetchRecipes = (searchTerm) => { | ||
| const BASE_ENDPOINT = `https://api.edamam.com/search?q=${searchTerm}&app_id=${APP_ID}&app_key=${APP_KEY}`; |
There was a problem hiding this comment.
I would even consider moving the BASE_ENDPOINT into it's own file.
| .then(res => res.json()) | ||
| .then(recipes => { | ||
| if(recipes.hits.length > 0) { | ||
| const data = recipes.hits.map(({recipe}) => { |
There was a problem hiding this comment.
Nice use of map!
Remember that passing in your adaption function is good for code reuse. Also, you don't need Object.assign here, but I like that you're making sure your being immutible.
You could do:
return {
name: recipe.label,
calories: Math.floor(recipe.calories),
image: recipe.image,
url: recipe.url
}
which returns a new object (without mutations)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
app: https://stephanie56.github.io/react-promise-homework/