-
-
Save joshburgess/90e0fe62e579dc3ef9d1631830d75cc8 to your computer and use it in GitHub Desktop.
react-basic Ref component
This file contains hidden or 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
| "use strict"; | |
| var React = require("react"); | |
| var ReactDOM = require("react-dom"); | |
| exports.makeRef = function(toMaybe) { | |
| var Ref = function(props) { | |
| this.DOMNode = null; | |
| return this; | |
| }; | |
| Ref.prototype = Object.create(React.Component.prototype); | |
| Ref.displayName = "Ref"; | |
| Ref.prototype.updateDOMNode = function() { | |
| var newDOMNode = ReactDOM.findDOMNode(this); | |
| if (this.DOMNode !== newDOMNode) { | |
| this.DOMNode = newDOMNode; | |
| this.forceUpdate(); | |
| } | |
| }; | |
| Ref.prototype.componentDidMount = function() { | |
| this.updateDOMNode(); | |
| }; | |
| Ref.prototype.componentDidUpdate = function() { | |
| this.updateDOMNode(); | |
| }; | |
| Ref.prototype.render = function() { | |
| return this.props.render(toMaybe(this.DOMNode)); | |
| }; | |
| return Ref; | |
| }; |
This file contains hidden or 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
| module Lumi.Components.Molecules.Ref where | |
| import Prelude | |
| import Data.Maybe (Maybe) | |
| import Data.Nullable (Nullable, toMaybe) | |
| import React.Basic (JSX, ReactComponent) | |
| import React.Basic.DOM.Events (DOMNode) | |
| type RefProps = | |
| { render :: Maybe DOMNode -> JSX | |
| } | |
| foreign import makeRef :: (Nullable ~> Maybe) -> ReactComponent RefProps | |
| ref :: ReactComponent RefProps | |
| ref = makeRef toMaybe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment