A lightweight React hook that automatically formats date input as the user types. Current version 1.0.11 (last updated 2023). It provides a custom hook useFormatDate that takes the onChange event, a state setter, and a special character separator. The hook formats the input into MM/DD/YYYY or other patterns. Minimal dependencies: only React. Differentiator: simpler than date-fns or moment for inline input masking.
npm install react-onchange-date-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage of useFormatDate hook to format date input on change.
Ensure useFormatDate() is called at the top level of a functional component.
Use default import: import useFormatDate from 'react-onchange-date-formatter'
Pass a single character like '/' or '-'.
Change to: import useFormatDate from 'react-onchange-date-formatter'
Only call useFormatDate() inside a functional component or custom hook.
Ensure specialCharacter is a single character, e.g., '/', '-', '.'