mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 19:00:56 +00:00
29 lines
738 B
JavaScript
29 lines
738 B
JavaScript
'use client';
|
|
import { useState } from 'react';
|
|
|
|
function getInputOnChange(setValue) {
|
|
return (val) => {
|
|
if (!val) {
|
|
setValue(val);
|
|
} else if (typeof val === "function") {
|
|
setValue(val);
|
|
} else if (typeof val === "object" && "nativeEvent" in val) {
|
|
const { currentTarget } = val;
|
|
if (currentTarget.type === "checkbox") {
|
|
setValue(currentTarget.checked);
|
|
} else {
|
|
setValue(currentTarget.value);
|
|
}
|
|
} else {
|
|
setValue(val);
|
|
}
|
|
};
|
|
}
|
|
function useInputState(initialState) {
|
|
const [value, setValue] = useState(initialState);
|
|
return [value, getInputOnChange(setValue)];
|
|
}
|
|
|
|
export { getInputOnChange, useInputState };
|
|
//# sourceMappingURL=use-input-state.mjs.map
|