Created
May 26, 2016 18:25
-
-
Save remarkablemark/3dbe3f3cf69b4b2dcdd0cd390419b488 to your computer and use it in GitHub Desktop.
Adjacent JSX elements
This file contains hidden or 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'; | |
| /** | |
| * 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 []; | |
| } | |
| }; |
This file contains hidden or 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'; | |
| /** | |
| * 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