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

Alphonso's code review #27

Open
camelPhonso opened this issue Oct 18, 2023 · 0 comments
Open

Alphonso's code review #27

camelPhonso opened this issue Oct 18, 2023 · 0 comments

Comments

@camelPhonso
Copy link

  • This concept was perfect for React!
    • Single page app
    • Lots of components being updated individually depending on your data
    • Crazy fun game
  • Looks like you grasped the potential of useState really well! The set up is great
  • Between me doing this review and actually submitting I saw you pushed a reducer, which is great stuff, but you could actually have achieved the result you were after by using a useEffect(). Here's how:
export default function checkPulse(stats){
	let cause = ''
	
	if(stats.age > 49) cause = 'being too old'
	if(stats.coffee > 9) cause = 'too much coffee'
	// etc ...
	return cause
}
useEffect(()=>{
	const cause = checkPulse(stats)
	// do it in one place yo! this is the beauty of useEffect
	if (cause !== ''){
		setAlive(false)
		setDeathCause(cause)
	}
}, [age, energy]) // useEffect runs every time one of the 'letal' stats changes
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

No branches or pull requests

1 participant