React JS – Render an array of items in JSX
Hello everybody.
Quick code snippet for JSX for rendering an array of items, instead of a single one, in a ReactJS component:
var React = require('react');
var MyComponent = React.createClass({
render: function() {
var myString = ["L","o","r","e","m"," ","i","p","s","u","m"];
return (
<div> {
myString.map(function(letter) {
return <span>{letter}</span>
})
} </div>
);
}
});
module.exports = MyComponent;
voilà!
No comments yet.