Responsive mortgage repayment calculator with React and typescript

Solution retrospective
Proud Of: Comma Formatting: Nailed input formatting with Intl.NumberFormat for commas (e.g., 1,000,000), keeping raw numbers in Zustand.
const formatDisplayValue = (value: number, allowDecimals: boolean = false) => { if (value === 0) return ''; return allowDecimals ? value.toString() : numberFormatter.format(value); };
Do Differently:
- Real-Time Validation: Add instant feedback on input changes, not just on submit.
Challenges and Solutions:
- Comma-Formatted Inputs: Challenge: Displaying commas (e.g., 1,000,000) while storing raw numbers required syncing UI and state.
Solution: Used Intl.NumberFormat for display, parsed inputs with replace(/,/g, '') for the store.
What specific areas of your project would you like help with?const handleNumberChange = (e, setter) => { const rawValue = e.target.value.replace(/,/g, ''); setter(Number(rawValue) || 0); };
I’d appreciate community feedback on Real-Time Validation: How can I efficiently implement instant input validation (e.g., check amount > 0 as users type) without performance issues?
const handleNumberChange = (e, setter, field) => { const rawValue = e.target.value.replace(/,/g, ''); const numValue = Number(rawValue) || 0; setter(numValue); setErrors((prev) => ({ ...prev, [field]: numValue <= 0 })); };
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Amiko Elvis's solution.
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