Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Age Calculator

@dangero1990

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I built this project this way because I wanted to try out some of React's more complex hooks rather than just using state for everything. Please comment with any critiques you may see. I'm looking to learn and get better :)

Community feedback

@RafaelSS427

Posted

Hi Andrew, you did a great job! I found points in your code that you can improve.

  1. I recommend using the useEffect hook instead of using a conditional operator in your FormInput component. For example instead of this:
  if (clear) {
    inputRef.current.value = null;
  }

Use this:

useEffect(() => {
        if (clear) {
            inputRef.current.value = null;
        }
    }, [clear, inputRef])
  1. The date validations do not work as they should. I recommend performing the validations with the Date object.
  2. You can improve the readability of your code by creating a custom hook for each context of your application and then using it. For example:
import { useContext } from 'react'
import { UserContext } from '../App'

export const useUserContext = () => {
    const state = useContext(UserContext);

    return {
        ...state
    }
}

Marked as helpful

0

@dangero1990

Posted

@RafaelSS427 thank you for your feedback. The custom hook makes a whole lot of sense, and I'm going to play around with your suggestions when I have some free time.

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord