diff options
Diffstat (limited to 'docs/src/utils')
-rw-r--r-- | docs/src/utils/hooks.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/src/utils/hooks.js b/docs/src/utils/hooks.js new file mode 100644 index 0000000..b8fb27b --- /dev/null +++ b/docs/src/utils/hooks.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +import { useState } from "react"; + +export const useInput = (initialValue) => { + const [value, setValue] = useState(initialValue); + + return { + value, + setValue, + bind: { + value, + onChange: (event) => { + const target = event.target; + setValue(target.type === "checkbox" ? target.checked : target.value); + }, + }, + }; +}; |