diff options
| author | Haishan <[email protected]> | 2020-10-31 18:18:04 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-11-01 17:42:52 +0800 |
| commit | ff1a39d04e53b428e34d46c55ecd6689189b5443 (patch) | |
| tree | 94a60abe3d28a1d729b877356bdd38d75ce655a5 /src/components/Input.js | |
| parent | e62c9165481ef12ee2310dee1c32f890b3fe4b78 (diff) | |
chore: run ts-migrate
Diffstat (limited to 'src/components/Input.js')
| -rw-r--r-- | src/components/Input.js | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src/components/Input.js b/src/components/Input.js deleted file mode 100644 index efdb6ca..0000000 --- a/src/components/Input.js +++ /dev/null @@ -1,42 +0,0 @@ -import PropTypes from 'prop-types'; -import React from 'react'; - -import s0 from './Input.module.css'; - -const { useState, useRef, useEffect, useCallback } = React; - -export default function Input(props) { - return <input className={s0.input} {...props} />; -} - -export function SelfControlledInput({ value, ...restProps }) { - const [internalValue, setInternalValue] = useState(value); - const refValue = useRef(value); - useEffect(() => { - if (refValue.current !== value) { - // ideally we should only do this when this input is not focused - setInternalValue(value); - } - refValue.current = value; - }, [value]); - const onChange = useCallback((e) => setInternalValue(e.target.value), [ - setInternalValue, - ]); - - return ( - <input - className={s0.input} - value={internalValue} - onChange={onChange} - {...restProps} - /> - ); -} - -Input.propTypes = { - value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - type: PropTypes.string, - onChange: PropTypes.func, - name: PropTypes.string, - placeholder: PropTypes.string, -}; |
