mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(webapp): invoice tax rate
This commit is contained in:
36
packages/webapp/src/hooks/useUncontrolled.ts
Normal file
36
packages/webapp/src/hooks/useUncontrolled.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
interface UseUncontrolledInput<T> {
|
||||
/** Value for controlled state */
|
||||
value?: T;
|
||||
|
||||
/** Initial value for uncontrolled state */
|
||||
initialValue?: T;
|
||||
|
||||
/** Final value for uncontrolled state when value and initialValue are not provided */
|
||||
finalValue?: T;
|
||||
|
||||
/** Controlled state onChange handler */
|
||||
onChange?(value: T): void;
|
||||
}
|
||||
|
||||
export function useUncontrolled<T>({
|
||||
value,
|
||||
initialValue,
|
||||
finalValue,
|
||||
onChange = () => {},
|
||||
}: UseUncontrolledInput<T>) {
|
||||
const [uncontrolledValue, setUncontrolledValue] = useState(
|
||||
initialValue !== undefined ? initialValue : finalValue,
|
||||
);
|
||||
|
||||
const handleUncontrolledChange = (val: T) => {
|
||||
setUncontrolledValue(val);
|
||||
onChange?.(val);
|
||||
};
|
||||
|
||||
if (value !== undefined) {
|
||||
return [value as T, onChange, true];
|
||||
}
|
||||
return [uncontrolledValue as T, handleUncontrolledChange, false];
|
||||
}
|
||||
Reference in New Issue
Block a user