Skip to content

Instantly share code, notes, and snippets.

@lfender6445
Forked from tadjohnston/Foo.js
Last active May 6, 2021 17:18
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lfender6445/d03af04a80ea4c7e86a2373fa6176be7 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Baz from 'baz'
class Foo extends Component {
static propTypes = {
baz: PropTypes.bool,
list: PropTypes.array,
}
static defaultProps = {
list: '',
}
items = (list) => {
const filteredList = list
.filter(i => i !== null)
.map(item => ({ bar: item.baz }))
return filteredList.map((item, index) => (
<Baz
key={index}
bar={item.bar}
something={item.bar}
/>
))
}
render() {
const { list: entries } = this.props
return (
<span>
{list && (
<div>
{`Count is ${this.props.count} for items: `} {this.items(list)}
</div>
)}
{!list && (
<>{`Count is ${this.props.count} for items: `} n/a</>
)}
</span>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment