-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Hogs, Sort Hogs, Filter Hogs #16
base: master
Are you sure you want to change the base?
Conversation
@@ -1,12 +1,17 @@ | |||
import React from "react"; | |||
import React, {useState} from "react"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import React, {useState} from "react"; | |
import React, { useState } from "react"; |
function App() { | ||
const [greaseFilter, setGreaseFilter] = useState('') | ||
const [sortByWeight, setSortByWeight] = useState('') | ||
|
||
return ( | ||
<div className="App"> | ||
<Nav /> | ||
<Nav setGreaseFilter={setGreaseFilter} setSortByWeight={setSortByWeight}/> | ||
<Menu hogs={hogs} greaseFilter={greaseFilter} sortByWeight={sortByWeight}/> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing got a little crazy here!
const Hog = ({hog, setSelectedHog, selectedHog}) => { | ||
|
||
const handleClick = (e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const Hog = ({hog, setSelectedHog, selectedHog}) => { | |
const handleClick = (e) => { | |
const Hog = ({hog, setSelectedHog, selectedHog}) => { | |
const handleClick = (e) => { |
if(hog!==selectedHog){ | ||
return ( | ||
<div className='pigTile'> | ||
<div id={hog.name} className='ui eight wide column' onClick={handleClick}> | ||
<h3>{hog.name}</h3> | ||
<img className='pigImg' src={hog.image}/> | ||
</div> | ||
</div> | ||
)} else { | ||
return( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What in the world happened here?!
import React, {useState} from "react"; | ||
import Hog from './Hog'; | ||
|
||
const Menu = ({ hogs, greaseFilter, sortByWeight}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be a better approach would be to handle the filtering and sorting in the parent component and only pass in the filtered and sorted set of hogs. Less props and better separation of concerns.
Used state to display a list of hogs with options to sort and filter them