Created
April 2, 2023 13:41
-
-
Save shameemreza/74b371fbb9d716fba7817684186efc39 to your computer and use it in GitHub Desktop.
Code for "Exposing React Component functions with fowardRef and useRef" Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { forwardRef, useRef } from 'react'; | |
const Input = forwardRef((props, ref) => { | |
const inputRef = useRef(null); | |
const getValue = () => { | |
return inputRef.current.value; | |
} | |
const isValid = () => { | |
const value = getValue(); | |
return value !== '' && value.length >= 3; | |
} | |
return ( | |
<input | |
type="text" | |
ref={inputRef} | |
{...props} | |
/> | |
) | |
}); | |
export { Input }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment