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

Feature/hooks #2

Merged
merged 14 commits into from
Mar 22, 2019
Merged

Feature/hooks #2

merged 14 commits into from
Mar 22, 2019

Conversation

andria-dev
Copy link
Contributor

Migrated code to hooks.

Changes

  • useReducer to handle complicated state without cluttering component
    • logic like incrementing/decrementing enemies is in reducer
    • so is checking the answer and creating a new problem
  • Moved logic (reducer) to separate file AppReducer.js
  • Placed handlers (i.e. handleModePicker) in useCallback calls to avoid re-rendering when not necessary
  • Created operatorsByMode, an object that matches a mode to an operator, to replace the lengthy switch statement to find out which mode belongs to which operator.
  • Replaced lengthy switch statement that checks if the entered answer matches the expected answer. The new solution uses eval to evaluate the problem with the dynamic variable operator
  • Made the random number generator allow a minimum as well, numbers are now inclusive -> randomNumberGenerator(1, 9) returns 1 <= x <= 9

Notes

Changing to hooks makes React DevTools not able to see non-primitive values of hooks, to remedy this you should use an experimental version of React DevTools (it looks better too lol)

GIF Screenshot of Experimental React DevTools

I also added a prettier.config.js file to make it so that when a contributor saves it doesn't reformat the entire file to their editor's style, but instead keeps it in the same style you've been writing code in (no semicolons, single quotes, tab width of 2).

@JesseRWeigel JesseRWeigel merged commit 3993cee into JesseRWeigel:master Mar 22, 2019
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