This is for diving deeper into React, including topics of: User Input with Forms and Events
Kowalski, are you there?
-
In this NASA Images Application I continued practicing handling user input with Froms and Events
-
External API from NASA Images API, root url:
https://images-api.nasa.gov
-
This connection returns images, with params of
q(query)
&media_type('image')
, given a search term- eg: saturn returns images related to saturn
-
What was learned:
- Component Design and Structure
- Forms to interact with user
- Building, modifying and handling Events and Submissions
- Connection of External API and figuring out how to request/retrieve/display data
- Axios was used alongside async await
- Refactoring a few components from uncontrolled to controlled
- Communcating from Child to Parent and incoking callbacks in Children
- Using Grid CSS to workout the wonky image displays and gaps
-
A few things that do not work in the App:
- Currently the application returns 100 images
- Currently the images returned still have minor spacing issues(some images are right on top of another)
- There isn't much of a functioning app, the interaction is solely searching for images within NASA
- A user will only be able to search for images and get a basic display(no comments, titles, etc)
-
SearchBar: Event Handlers
- With an event handler, take an input/form tag
- Pass a callback() to a specifically named props(
<form onSubmit={this.onFormSubmit}
, etc) - When that tag/element emits event, that callback() will be called
- Rule to keep in mind: anytime there is a cb(), be safe to use ES6
=>()
syntax, which will bind the function and have the appropriate value ofthis
- With Props system, only communicate from Parent down to Child(later an issue)
- To communicate from Child to Parent, pass a cb() from Parent to Child, then Child will call the cb()
-
PhotoList: Render photos, a list of photos
- Map function, whenever rendering a list, probably will reach for Map function
- Any time a list is made, define a
key
on the root element of that list that is consistent and unchanging
- eg:
key={image.href}
,href
used becauseid
wasn't present and href was still very unique to each image
-
ImageCard: React Ref System
- Reach into DOM to interact with an individual element
- Ref is created in the
constructor()
and wired up to an element passed as a ref property - Ref can be accessed later and handle the actual DOM node
-
Grid CSS System
- Not completely necessary
- This is still fairly new and undergoing changes
- Great reason to use for figuring out how the Ref system works