Skip to content

Instantly share code, notes, and snippets.

@minmaxdata
Last active August 4, 2018 22:37
Show Gist options
  • Save minmaxdata/859ed5c0ee2aed4d8c0e7776e869526c to your computer and use it in GitHub Desktop.
Save minmaxdata/859ed5c0ee2aed4d8c0e7776e869526c to your computer and use it in GitHub Desktop.
An example using array .map()
{questions.map((question, index) => (
<Card
key={index}
question={question.question}
answer={question.answer}
index={index}
/>
))}
{Object.keys(decks).map(key => {
const { title, uuid, questions } = decks[key];
return (
<View key={uuid}>
<Text>{title}</Text>
<Text>{questions.length}</Text>
</View>
);
})}
JSON.stringify(this.state)
render() {
const metaInfo = getMetricMetaInfo()
return (
<View>
{Object.keys(metaInfo).map((key) => {
const { getIcon, type, ...rest } = metaInfo[key]
const value = this.state[key]
return (
<View key={key}>
{getIcon()}
{type === 'slider'
? <UdaciSlider
value={value}
onChange={(value) => this.slide(key, value)}
{...rest}
/>
: <UdaciSteppers
value={value}
onIncrement={() => this.increment(key)}
onDecrement={() => this.decrement(key)}
{...rest}
/>}
</View>
)
})}
</View>
)
}
sortPostsByCategory = (category) => {
this.setState({sortBy: category})
const newObj = {};
Object.keys(initialPosts).map((post) => {
if(initialPosts[post]['category'] === category) {
newObj[post] = initialPosts[post]
}
})
this.setState({posts: newObj})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment