Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created April 2, 2023 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shameemreza/1e05d6e694ce5e4b0d11c421569020b2 to your computer and use it in GitHub Desktop.
Save shameemreza/1e05d6e694ce5e4b0d11c421569020b2 to your computer and use it in GitHub Desktop.
Code for "Exposing React Component functions with fowardRef and useRef" Article
import { useRef } from 'react';
import { Input } from './Input';
const App = () => {
const inputRef = useRef(null);
const handleSubmit = (event) => {
event.preventDefault();
const value = inputRef.current.getValue();
const isValid = inputRef.current.isValid();
console.log(value, isValid);
}
return (
<form onSubmit={handleSubmit}>
<Input ref={inputRef} />
<button type="submit">Submit</button>
</form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment