Skip to content

Instantly share code, notes, and snippets.

@robmclarty
Last active August 29, 2015 14:24
Show Gist options
  • Save robmclarty/add7976ce87c879197c7 to your computer and use it in GitHub Desktop.
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
'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