Last active
January 3, 2017 18:55
-
-
Save lemonmade/9aa309a74565cab479a87be590416e0d to your computer and use it in GitHub Desktop.
To type or not to type
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
// @flow | |
import React, {Component} from 'react'; | |
import ReactDOM from 'react-dom'; | |
type TestDetails<T: HTMLElement> = { | |
node: HTMLElement, | |
}; | |
type Props = { | |
children?: React$Element<any>, | |
onTestReady?: <T: HTMLElement>(details: TestDetails<T>) => void, | |
}; | |
export default class Tester extends Component { | |
props: Props; | |
performTest() { | |
const {onTestReady, children} = this.props; | |
if (children == null || onTestReady == null) { | |
return; | |
} | |
onTestReady({node: ReactDOM.findDOMNode(this).children[0]}); | |
} | |
componentDidMount() { | |
this.performTest(); | |
} | |
componentDidUpdate() { | |
this.performTest(); | |
} | |
render() { | |
const {children} = this.props; | |
if (children == null) { return null; } | |
return <div>{children}</div>; | |
} | |
} |
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 * as React from 'react'; | |
import {findDOMNode} from 'react-dom'; | |
interface TestDetails<E extends HTMLElement> { | |
node: E, | |
} | |
interface Props { | |
children?: React.ReactNode, | |
onReady: <E extends HTMLElement>(details: TestDetails<E>) => void, | |
} | |
export default class Tester extends React.Component<Props, {}> { | |
private performTest() { | |
const {onReady, children} = this.props; | |
if (children == null) { return; } | |
onReady({ | |
node: findDOMNode(this).children[0], | |
}) | |
} | |
componentDidMount() { | |
this.performTest(); | |
} | |
componentDidUpdate() { | |
this.performTest(); | |
} | |
render() { | |
const {children} = this.props; | |
if (children == null) { return null; } | |
return <div>{children}</div>; | |
} | |
} |
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, {Component, PropTypes} from 'react'; | |
import {findDOMNode} from 'react-dom'; | |
export default class Tester extends Component { | |
static propTypes = { | |
children: PropTypes.node, | |
onReady: PropTypes.func, | |
}; | |
performTest() { | |
const {onReady, children} = this.props; | |
if (children == null) { return; } | |
onReady({ | |
node: findDOMNode(this).children[0], | |
}) | |
} | |
componentDidMount() { | |
this.performTest(); | |
} | |
componentDidUpdate() { | |
this.performTest(); | |
} | |
render() { | |
const {children} = this.props; | |
if (children == null) { return null; } | |
return <div>{children}</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment