Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2023 13:42
  • 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
What would you like to do?
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) => {
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment