Created
June 22, 2016 06:06
-
-
Save kjessec/4b507a0df472a2938fafe106cc9fd3ef 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
'use strict'; | |
import React from 'react'; | |
class BaseComponent extends React.Component { | |
componentDidMount() { | |
// ref error will be given, | |
// this.refs.root === <div> | |
// this.refs.subrender === null | |
console.log(this.refs); | |
} | |
render() { | |
const { | |
StatelessFunctionSubRender | |
} = this; | |
return ( | |
<div ref="root"> | |
<StatelessFunctionSubRender ref="subrender"/> | |
</div> | |
); | |
} | |
// despite this is a member method of BaseComponent class, | |
// in BaseComponent's render() we use it as a plain function (not aware of component context) | |
// thus treated as a pure stateless function | |
StatelessFunctionSubRender(props) { | |
return ( | |
<div>{props.children}</div> | |
); | |
} | |
} | |
export default BaseComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment