Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created April 2, 2023 13:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Code for "Exposing React Component functions with fowardRef and useRef" Article
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