See Headers Below For Step By Step Outline
Note: each step has a corresponding commit with the implemented actions on the solution branch of this repo.
Fork and clone to get a local copy of the app.
Check out to the solution branch.
npm install
npm start
Spend time playing around with the completed exercise. Look at index.js
. Think about how you would separate your different components and functionality.
A solution with giphy gif searching is available in a react-giphy-solution repo.
Move back to the master
branch to build out the app yourself! Remove your node_modules
folder manually, since it's included in .gitingore
. Re-npm install
any packages you will need.
Before we start building our React app, let's create a HelloWorld
component just to make sure that we've tied everything together properly.
- In your
/src
directory, configure yourApp.js
andindex.js
files to render aHelloWorld
component. - Run
npm start
and make sure everything is working.
- Rename
App.js
toHome.js
to better indicate the purpose of the file. Make sure to update references to this file elsewhere in your application accordingly. - Create a Home component that returns a container
<div>
element, which should in turn contain a<h1>
element. - Render that component to the DOM in your app's main
index.js
file
- Create a new file for your
Search
component. - Define a
Search
component that renders a search form. This can be a simple form with a single input and submit button. - Import the
Search
file to yourHome
file. - Render the
Search
component in theHome
component.
- Define your
Search
component's initial state. It should have aquery
value that corresponds to a search term. - Define a function that is triggered whenever the user submits the Search form. Start by just logging
"searched!"
to make sure it works.- Use an event listener to attach this function to your form. Try googling
onSubmit
.
- Use an event listener to attach this function to your form. Try googling
- Define a function that updates your
query
value in state whenever a change is made to the input field. You can do this using anonInput
function on your text box, or by usingref
. - Update your submit function so that it now logs the
query
value in state.
- Create a new
SearchContainer
component that that renders theSearch
component. ThisSearchContainer
will also handle search results. - Refactor your
Search
component so that it only renders a UI. It should use properties passed into the Search component. - Move all of the business logic related to state for the search into the
SearchContainer
component. TheSearchContainer
component should still render theSearch
component, with any necessary properties.
- Define a
Results
component that will take in a collection of gif objects and render each one'ssource
url as well as a fixed height image. Go ahead an look at the Giphy search documentation to see the structure of the JSON it sends. - Update your
SearchContainer
component's state to include whether the user has submitted a search. - Update
SearchContainer
's state to include a list of results. - If a user has searched, instead of rendering the
Search
component, render aResults
component with hard coded data. - This is starting to look like a single page app, but we don't have routing yet. If you'd like, update the component so that the search bar and any results are always displayed on the page, and clear out old results when a new search is submitted.
click for simplified hard-coded gif data you could use
{
"data": [
{
"type": "gif",
"id": "iuHaJ0D7macZq",
"url": "http://giphy.com/gifs/cat-day-tomorrow-iuHaJ0D7macZq",
"source": "https://www.reddit.com/r/CatGifs/comments/5f0h9a/tomorrow_is_legs_day/",
"rating": "pg",
"images": {
"fixed_height": {
"url": "http://media4.giphy.com/media/iuHaJ0D7macZq/200.gif"
}
}
},
{
"type": "gif",
"id": "Z1kpfgtHmpWHS",
"url": "http://giphy.com/gifs/cat-way-make-Z1kpfgtHmpWHS",
"source": "http://shewhoseeks.blogspot.com/2016/03/cat-gifs-that-make-me-laugh-way-more.html",
"rating": "g",
"images": {
"fixed_height": {
"url": "http://media4.giphy.com/media/Z1kpfgtHmpWHS/200.gif"
}
}
}
],
"meta": {
"status": 200,
"msg": "OK"
},
"pagination": {
"total_count": 1947,
"count": 25,
"offset": 0
}
}
- With the API we're using, you don't need to register for an API key. Go ahead an look at the documentation to determine the API's proper usage.
- We're going to be searching the giphy API based on a word or phrase to return a collection of results.
- Load in jQuery, and use it to make an HTTP request to the API search endpoint using the user's query.
- Pass the data to the Results component to be displayed.
- Load in Bootstrap CDN in
index.html
. - Modify UI to include Bootstrap classes.
- Create a
styles
directory and make a file for your CSS rule definitions - this will be written in Javascript!. - Load in that file in any component and then use that to apply inline styling.
- Create a
Details
component that renders information about a single gif. - When a user clicks on a gif in the results view, render the detail UI.