Skip to content

Instantly share code, notes, and snippets.

@jnfrati
Created August 21, 2020 14:35
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 jnfrati/3d00efe82c76fa009b34392a121ff474 to your computer and use it in GitHub Desktop.
Save jnfrati/3d00efe82c76fa009b34392a121ff474 to your computer and use it in GitHub Desktop.
Forward Ref and useImperativeHandle propTypes
import React from 'react';
import {node} from 'prop-types';
const RandomComponent = React.forwardRef((props, ref) => {
React.useImperativeHandle(ref, () => ({
someFunction: () => {
return 'someData';
},
someOtherFunction: () => {
}
}), []);
return (
<>
{props.children}
</>
)
})
RandomComponent.propTypes = {
children: node.isRequired,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment