Created
September 25, 2015 15:44
-
-
Save gandhiShepard/a1066b831997212c967c to your computer and use it in GitHub Desktop.
React .filter and .map example
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
// via: Learn Raw React — no JSX, no Flux, no ES6, no Webpack… | |
// http://jamesknelson.com/learn-raw-react-no-jsx-flux-es6-webpack | |
var contacts = [ | |
{key: 1, name: "James Nelson", email: "[email protected]"}, | |
{key: 2, name: "Bob"} | |
] | |
var listElements = contacts | |
.filter(function(contact) { return contact.email; }) | |
.map(function(contact) { | |
return React.createElement('li', {key: contact.key}, | |
React.createElement('h2', {}, contact.name), | |
React.createElement('a', {href: 'mailto:'+contact.email}, contact.email) | |
) | |
}) | |
var rootElement = | |
React.createElement('div', {}, | |
React.createElement('h1', {}, "Contacts"), | |
// If your `children` is an array, you'll need to give each one a unique `key` | |
// prop. I'll explain why a little later. | |
React.createElement('ul', {}, listElements) | |
) | |
ReactDOM.render(rootElement, document.getElementById('react-app')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am write my code like this:
const mika = pera.filter(id=>{
return (id.id=== 2);
});
const mika1 = mika.map((primer,i)=>{
return(
{primer.id} {primer.title}
);
});
but I can't format this data in return section of component divide, accept if I do that in constant mika1. How must write code for another solution?