Skip to content

Instantly share code, notes, and snippets.

@Razzwan
Last active May 12, 2017 14:57
Show Gist options
  • Save Razzwan/9d8df96998cb1e71028ae0bbd5b54781 to your computer and use it in GitHub Desktop.
Save Razzwan/9d8df96998cb1e71028ae0bbd5b54781 to your computer and use it in GitHub Desktop.
Component
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { View } from 'react-native'
class Component extends Component {
static propTypes = {
styles: PropTypes.object,
}
state = {
showAll: true,
}
componentWillMount () {
if (this.props.list.length === 0) {
this.props.onGetList()
}
}
handleButtonShowAllClick = (e) => {
this.setState({ showAll: !this.state.showAll })
}
render () {
const { styles, list } = this.props
const { showAll } = this.state
return (
<View style={styles.box}>
{sowAll && list.map(item => (
<Text>{item.name}</Text>
))}
<Text style={styles.description}>Description</Text>
<Button onClick={this.handleButtonShowAllClick}>Show all toggle</Button>
</View>
)
}
}
export default Component
import { connect } from 'react-redux'
import Component from './Component'
import styles from './styles'
export default connect(
store => ({
styles: styles,
})
)(Component)
import colors from 'styles/palette'
const styles = {
box: {
backgroundColor: colors.baseColor,
},
text: {
color: colors.secondColor,
},
}
export default styles
@Razzwan
Copy link
Author

Razzwan commented May 12, 2017

All this files located in a single folder with name Component

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