I have a reusable Input built on top-of Antd Input.
Now I have a prop trim which is a boolean.
If trim is true, we trim the leading and trailing white spaces as below.
export default function MyInput({ trim, onChange, ...props }) {
const handleChange = (e) => {
if (trim) {
e.target.value = e.target.value.trim();
}
onChange?.(e);
};
return <Input onChange={handleChange} {...props} />;
}
This works completely fine.
Code available here
But is it a good approach?
If not what's the better alternative for achieving this functionality?