Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Created May 26, 2016 18:25
Show Gist options
  • Select an option

  • Save remarkablemark/3dbe3f3cf69b4b2dcdd0cd390419b488 to your computer and use it in GitHub Desktop.

Select an option

Save remarkablemark/3dbe3f3cf69b4b2dcdd0cd390419b488 to your computer and use it in GitHub Desktop.
Adjacent JSX elements
'use strict';
/**
* Module dependencies.
*/
const React = require('react');
/**
* Function that returns adjacent JSX elements.
*
* @return {Array} - The array of React elements.
*/
module.exports = function() {
const props = this.props || {};
if (props.list && props.list.constructor === Array) {
return props.list.map(function(item, index) {
return (
<li key={index}>
{typeof item === 'string' ? item.toUpperCase() : item}
</li>
);
});
} else {
return [];
}
};
'use strict';
/**
* Module dependencies.
*/
const React = require('react');
const adjacentElements = require('./adjacent-elements.jsx');
/**
* Component.
*/
module.exports = React.createClass({
getDefaultProps: function() {
return {
list: ['foo', 'bar', 'baz']
};
},
render: function() {
return (
<ol>
{/* ensure the component context is bound */}
{adjacentElements.apply(this)}
</ol>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment