Last active
August 29, 2015 14:24
-
-
Save robmclarty/add7976ce87c879197c7 to your computer and use it in GitHub Desktop.
An alternative method of defining a React component in ES6, mixing ideas from Crockford's better parts and https://gist.github.com/jquense/47bbd2613e0b03d7e51c
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'; | |
import assign from 'object-assign'; | |
export default function Notification(props, context) { | |
const propTypes = { | |
messsage: React.PropTypes.string, | |
autoHide: React.PropTypes.bool, | |
isOpen: React.PropTypes.bool, | |
}; | |
const defaultProps = { | |
message: '', | |
autoHide: false, | |
isOpen: false, | |
}; | |
function privateMethod() { | |
// do something privately | |
} | |
function render() { | |
let html = ( | |
<div className="notification"> | |
{this.props.message} | |
</div> | |
); | |
return this.props.isOpen | |
? html | |
: false; | |
} | |
return assign({}, React.Component.prototype, { | |
props, | |
propTypes, | |
defaultProps, | |
context, | |
render, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment