Skip to content

Instantly share code, notes, and snippets.

@amitasaurus
Created May 4, 2024 04:44
Show Gist options
  • Save amitasaurus/b03e2d9d302bdc4884635521e9a3b7b4 to your computer and use it in GitHub Desktop.
Save amitasaurus/b03e2d9d302bdc4884635521e9a3b7b4 to your computer and use it in GitHub Desktop.
forwardRef simple syntax
interface MyComponentProps {
// Your component props here
}
const MyComponent = forwardRef<HTMLInputElement, MyComponentProps>(
(props, ref) => {
// Render your component with the ref attached to the desired element
return <input ref={ref} {...props} />;
}
);
export default MyComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment