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

PS complete - Peter #4

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

Conversation

PeterTheDeveloper
Copy link

No description provided.

@ROgbonna1 ROgbonna1 requested a review from ipc103 April 29, 2020 19:00
Copy link

@ipc103 ipc103 left a comment

Choose a reason for hiding this comment

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

Hey @PeterTheDeveloper - @ROgbonna1 asked me to take a look at your PR and leave a review. Overall nice work on this! I left some comment inline - biggest thing to change would be to use a prop for the UserCard instead of hard-coding it to a single userId, but overall this was well put together and your getUsers function was really easy to read. Also, the stying looked pretty cool from Materialize - nice work putting that together too! If you get a chance, see if you can use a prop to make your UserCard component more re-usable. Feel free to respond to any of the comments if you have questions!

@@ -0,0 +1,62 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
Copy link

Choose a reason for hiding this comment

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

Nice work applying the material UI styles - the card looks pretty nice!

const [isLoading, setIsLoading] = React.useState(true);

React.useEffect(() => {
getUsers('3')
Copy link

Choose a reason for hiding this comment

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

Nice work building out the getUsers function. One small note is that since we're only fetching one user, I'd probably name the function getUser instead - just a small change, but it helps let other developers know what to expect.

Copy link

Choose a reason for hiding this comment

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

One other thing here - right now, this component is only capable of rendering out the user with the ID of '3', but it could be capable of doing way more. Instead of hard-coding this value here, I'd have the component take in a prop called userId that you could use to fetch the data. That way, you could render out this component a bunch of different times.

@@ -0,0 +1,19 @@
import { UserCard } from "./UserCard";
Copy link

Choose a reason for hiding this comment

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

You shouldn't need to import this here - this function will get used in the UserCard Theoretically, this function could be used in other spots of your app too, it's really flexible!


async function getUsers(userID) {

const url = `https://reqres.in/api/users/${userID}`;
Copy link

Choose a reason for hiding this comment

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

👍 👍 - nice work giving this variable a name! Small thing, but it makes this way easier to read.

const results = JSON.parse(data);
return results.data;
}
catch (err) {
Copy link

Choose a reason for hiding this comment

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

Also 👍 👍 to catching this - you could alsocatch in you component to display some type of error there if you wanted to as well.

setUser(data);
setIsLoading(false);
});
}, []);
Copy link

Choose a reason for hiding this comment

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

If you did update this to use a userId prop, you'd also want to include that here in the dependency array so that the useEffect callback could fire if that changed.

});

const UserCard = () => {
const [user, setUser] = React.useState({
Copy link

Choose a reason for hiding this comment

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

This is kind of cool - when I did this, I used null as the default value for the user, but having the keys here lets you know what to expect to be included, which is nice. I'd probably use null for the property values instead of loading..., as the loading message will display kind of weird for things like the avatar.

{
  avatar: null,
  email: null,
  //...etc 
}

}, []);

const classes = useStyles();

Copy link

Choose a reason for hiding this comment

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

Instead of depending on your default '...loading' values in state, you can use the isLoading prop to do an early return for the loading message.

if (isLoading){
  return <p>...Loading</p> 
}

I think that makes things a bit easier to reason about.

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