Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Lsimmons98
Copy link

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

@@ -1,12 +1,17 @@
import React from "react";
import React, {useState} from "react";

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 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>
);
}

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 on lines +3 to +5
const Hog = ({hog, setSelectedHog, selectedHog}) => {

const handleClick = (e) => {

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 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(

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}) => {

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