Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shiftyp/25e05496bbe48df39c57c8fe9a9e3552 to your computer and use it in GitHub Desktop.
Save shiftyp/25e05496bbe48df39c57c8fe9a9e3552 to your computer and use it in GitHub Desktop.
Hey, I'm trying to access my state in the handle toggle event. Right now, on line 10, 'tilesData' is only set to run this toggle of expanding/collapsing the card on position 0 of the array...
export default class Cardz extends React.Component {
constructor(props) {
super(props);
this.state = {
tilesData: [
{
img: 'http://loremflickr.com/640/400/breakfast/all',
title: 'Breakfast',
author: 'jill111',
featured: true,
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/burger/all',
title: 'Tasty burger',
author: 'pashminu',
expanded: true,
},
{
img: 'http://loremflickr.com/640/400/camera/all',
title: 'Camera',
author: 'Danson67',
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/morning/all',
title: 'Morning',
author: 'fancycrave1',
featured: true,
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/hats/all',
title: 'Hats',
author: 'Hans',
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/honey/all',
title: 'Honey',
author: 'fancycravel',
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/vegetables/all',
title: 'Vegetables',
author: 'jill111',
expanded: false,
},
{
img: 'http://loremflickr.com/640/400/plant/all',
title: 'Water plant',
author: 'BkrmadtyaKarki',
expanded: false,
},
]
};
}
handleToggle(event, toggle) {
var newState = update(this.state, {tilesData: {0: {expanded: {$set: toggle}}}})
console.log(this.state.tilesData)
this.setState(newState);
};
render() {
return (
<div>
{this.state.tilesData.map((tile) => (
<Card
style={{flex: .5, flexDirection:'row'}}
onClick={this.handleToggle.bind(this)}
expanded={tile.expanded}
onExpandChange={this.handleExpandChange}
style={{width: '60%',
marginLeft: '10rem'}} >
<CardHeader
title={tile.title}
subtitle={"Subtitle"}
avatar="http://lorempixel.com/100/100/nature/"
actAsExpander={true}
showExpandableButton={true}
/>
<CardText>
</CardText>
<CardMedia
expandable={true}
overlay={<CardTitle title="Overlay title" subtitle="Overlay subtitle" />}
>
<img src={tile.img} />
</CardMedia>
<CardTitle title="Card title" subtitle="Card subtitle" expandable={true} />
<CardText expandable={true}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec mattis pretium massa. Aliquam erat volutpat. Nulla facilisi.
Donec vulputate interdum sollicitudin. Nunc lacinia auctor quam sed pellentesque.
Aliquam dui mauris, mattis quis lacus id, pellentesque lobortis odio.
</CardText>
<CardActions>
<FlatButton label="Expand" onTouchTap={this.handleExpand.bind(this)} />
<FlatButton label="Reduce" onTouchTap={this.handleReduce.bind(this)} />
</CardActions>
</Card>
))}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment