Skip to content

Instantly share code, notes, and snippets.

@gandhiShepard
Created September 25, 2015 15:44
Show Gist options
  • Save gandhiShepard/a1066b831997212c967c to your computer and use it in GitHub Desktop.
Save gandhiShepard/a1066b831997212c967c to your computer and use it in GitHub Desktop.
React .filter and .map example
// 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'))
@Trajanovic
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment