Skip to content

Instantly share code, notes, and snippets.

@kjessec
Created June 22, 2016 06:06
Show Gist options
  • Save kjessec/4b507a0df472a2938fafe106cc9fd3ef to your computer and use it in GitHub Desktop.
Save kjessec/4b507a0df472a2938fafe106cc9fd3ef to your computer and use it in GitHub Desktop.
'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