Last active
November 27, 2019 11:33
-
-
Save Bolza/b5ab1f040b2906662d6560403aa21755 to your computer and use it in GitHub Desktop.
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
class ReferenceWrapper extends Component { | |
static displayName = 'ReferenceWrapper' | |
render() { | |
return Children.only(this.props.children) | |
} | |
} | |
const renderWrapper = WrappedComponent => { | |
function SizeMeRenderer(props) { | |
const toRender = renderPlaceholder ? ( | |
<Placeholder className={className} style={style} /> | |
) : ( | |
<WrappedComponent {...renderProps} {...restProps} /> | |
) | |
return <ReferenceWrapper ref={explicitRef}>{toRender}</ReferenceWrapper> | |
} | |
} | |
// using forwardRef | |
const FancyButton = React.forwardRef((props, ref) => ( | |
<button ref={ref} className="FancyButton"> | |
{props.children} | |
</button> | |
)); | |
// You can now get a ref directly to the DOM button: | |
const ref = React.createRef(); | |
<FancyButton ref={ref}>Click me!</FancyButton>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment