Skip to content

Instantly share code, notes, and snippets.

@ajcronk
Created November 20, 2016 04:42
Show Gist options
  • Save ajcronk/c7adb6e501d17986ef98f19400da0f86 to your computer and use it in GitHub Desktop.
Save ajcronk/c7adb6e501d17986ef98f19400da0f86 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import FlipMove from 'react-flip-move';
class App extends React.Component {
constructor(props) {
super(props);
this.handeClick = this.handeClick.bind(this);
this.state = {
items:[
{ id:"Item1", visible: true },
{ id:"Item2", visible: false },
{ id:"Item3", visible: false },
]
}
}
handeClick() {
const items = this.state.items;
items[1].visible = true;
this.setState({items: items});
}
render() {
return (
<div>
<Button onClick={this.handeClick}/>
<FlipMove>
{/* works */}
{this.state.items.filter(item => item.visible).map(item => <Item key={item.id} item={item} />)}
{/* does not work */}
{/* {this.state.items.map(item => <Item key={item.id} item={item} />)} */}
</FlipMove>
</div>
);
}
}
class Item extends Component {
render() {
if (!this.props.item.visible) {
return null;
}
else {
return (
<li>{this.props.item.id}</li>
);
}
}
}
class Button extends Component {
render() {
return (
<button onClick={this.props.onClick}>Click</button>
);
}
}
export default App;
create-react-app flip-move-empty
cd flip-move-empty
npm install react-flip-move
npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment