Created
August 21, 2020 14:35
-
-
Save jnfrati/3d00efe82c76fa009b34392a121ff474 to your computer and use it in GitHub Desktop.
Forward Ref and useImperativeHandle propTypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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