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

Hooks version #18

Merged
merged 24 commits into from
May 22, 2020
Merged

Hooks version #18

merged 24 commits into from
May 22, 2020

Conversation

mohqarmout
Copy link
Owner

@mohqarmout mohqarmout commented May 10, 2020

Trying to figure out Hooks & apply it to the core project

@mohqarmout mohqarmout self-assigned this May 10, 2020
@mohqarmout mohqarmout linked an issue May 10, 2020 that may be closed by this pull request
@mohqarmout mohqarmout added the help wanted Extra attention is needed label May 10, 2020
Copy link
Collaborator

@leggomuhgreggo leggomuhgreggo left a comment

Choose a reason for hiding this comment

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

Dude good separation of concerns. Definitely thoughtful code.

this.setState({
error: false,
});
const withErrorHandler = (WarppedComponent, axios) => props => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the dependency injection of axios

I'm curious what inspired you to pass it in like that.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It is just way listing to Axios call before reach then, catch
AKA global error handler

mounted.current = true;
return () => {
axios.interceptors.request.eject(axiosRequest);
axios.interceptors.response.eject(axiosResponse);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Damn this is some advanced axios API moves -- neat!

@mohqarmout mohqarmout removed the help wanted Extra attention is needed label May 10, 2020
@mohqarmout
Copy link
Owner Author

For some reason, GitHub action -- the build failed to Webpack console warns

@leggomuhgreggo keep that in mind

@mohqarmout mohqarmout added the help wanted Extra attention is needed label May 11, 2020
@mohqarmout mohqarmout added Done question Further information is requested Awaiting Review This PR is ready and waiting for review and removed On progress labels May 12, 2020
@mohqarmout
Copy link
Owner Author

Hope this PR satisfy you I did my best to mack it optimal
it tasks me a lot to make it happen because of Ramdan and my lovely laptop, sorry for that
anyway thanks for your time man, I appreciated it.

Copy link
Collaborator

@leggomuhgreggo leggomuhgreggo left a comment

Choose a reason for hiding this comment

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

Solid work!

I felt bad or taking so long to review so I was pretty thorough, but hope it doesn't give the wrong impression -- the changes are dank 👍

There might be one or two spots where you could eliminate a hook if the code organized a little different but still totally works.

LMK if you have any questions 👍

'prettier/react',
'plugin:jsx-a11y/recommended',
'plugin:react-redux/recommended',
'plugin:jest/recommended',
'plugin:jest/style'
'plugin:jest/style',
'plugin:prettier/recommended',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note (no change required): One thing about the prettier plugin is that -- if some other plugin has formatting rules that conflict with prettier -- whichever plugin is later in the extends: [...] array will override the other. So keeping prettier near the last is a good practice 👍

<main className={classes.Content}>{children}</main>
</>
);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

valid: false,
touched: false,
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: I'd recommend extracting initial state -- keeping config separate is going to make life easier

authError,
authenticated,
authRedirect,
buildingBurger,
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): This is slightly out of scope but -- it's good practice to observe the boolean naming convention where you prefix boolean vars with simple verbs like "is" "has" "can" etc.

Incidentally, your naming choices are really solid -- like way better than most of the code I see 👍

if (buildingBurger) {
authSetRedirectPath('/checkout');
} else {
authSetRedirectPath('/');
}
}
}, [buildingBurger]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


updatePurchaseState = () => {
const { ingredients } = this.props;
const updatePurchaseState = useCallback(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

const disabledInfo = {
}, [ingredients]);

let orderSummary = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Is this state?

}, [ingredients]);

let orderSummary = null;
let burger = <Spinner />;
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: might try to rewrite this as a ternary either inline or an extracted render method -- that way you can skip the mutation.

orderSummary = (
<OrderSummary
ingredients={ingredients}
}, [ingredients]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Interesting! Hmm might be a slightly indirect control flow mechanism but totally works

Comment on lines +121 to +125
for (const key in disabledInfo) {
if ({}.hasOwnProperty.call(disabledInfo, key)) {
disabledInfo[key] = disabledInfo[key] <= 0;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: I'd try to avoid for loops if possible since it's usually a sing of mutation and the syntax is a little gnarly. Also curious what inspired the hasOwnProperty approach?

@mohqarmout mohqarmout merged commit be49e13 into master May 22, 2020
@mohqarmout mohqarmout deleted the 17-hooks branch May 22, 2020 18:48
@mohqarmout mohqarmout added fast-follow and removed Awaiting Review This PR is ready and waiting for review help wanted Extra attention is needed question Further information is requested labels May 23, 2020
@mohqarmout mohqarmout mentioned this pull request May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React hooks
2 participants