Resposnive age calculator(React,Tailwind,Typescript)
Design comparison
Solution retrospective
I am interested if my typescript and react is up to standard to a junior developers! Thank you
Community feedback
- @TripouillePosted over 1 year ago
Hello Filip!
Great job on the results! If you don't mind, I have a few suggestions for improvement. Firstly, consider leveraging available packages like Moment or Date-fns for handling dates, and a JSON schema along with a validation library for form validation. This can help streamline your code and ensure consistency.
Additionally, it's advisable to minimize the use of setState inside functions, such as in the case of setUserAge within the calculateAge function. This can make the code harder to predict, as calling calculateAge does not indicate that userAge will be updated. It may be better to refactor this logic to improve code readability.
if (validateInput()) { const age = calculateAge( ...); setUserAge(age); }
Furthermore, consider extracting the calculateAge function out of the component, which would make it easier to test using tools like Jest or Vitest. This can aid in writing effective unit tests for your code.
Overall, these suggestions can enhance the maintainability and reliability of your code. Keep up the good work!
Marked as helpful1@FilipCondacPosted over 1 year ago@Tripouille thank you very much for the feedback. It is really the feedback I was looking for to improve my techniques and be more efficient in Typescript. This was appreciated!
I will make these changes!
1
Please log in to post a comment
Log in with GitHubJoin 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