Skip to content

Display Hogs, Sort Hogs, Filter Hogs#16

Open
Lsimmons98 wants to merge 3 commits intolearn-co-curriculum:masterfrom
Lsimmons98:workingBranch
Open

Display Hogs, Sort Hogs, Filter Hogs#16
Lsimmons98 wants to merge 3 commits intolearn-co-curriculum:masterfrom
Lsimmons98:workingBranch

Conversation

@Lsimmons98
Copy link
Copy Markdown

Used state to display a list of hogs with options to sort and filter them

Comment thread src/components/App.js
@@ -1,12 +1,17 @@
import React from "react";
import React, {useState} from "react";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import React, {useState} from "react";
import React, { useState } from "react";

Comment thread src/components/App.js
Comment on lines 7 to 17
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>
);
}
Copy link
Copy Markdown

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!

Comment thread src/components/Hog.js
Comment on lines +3 to +5
const Hog = ({hog, setSelectedHog, selectedHog}) => {

const handleClick = (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Hog = ({hog, setSelectedHog, selectedHog}) => {
const handleClick = (e) => {
const Hog = ({hog, setSelectedHog, selectedHog}) => {
const handleClick = (e) => {

Comment thread src/components/Hog.js
Comment on lines +10 to +19
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(
Copy link
Copy Markdown

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?!

Comment thread src/components/Menu.js
import React, {useState} from "react";
import Hog from './Hog';

const Menu = ({ hogs, greaseFilter, sortByWeight}) => {
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants