I'm using React and the CSSTransitionGroup component to switch between two sets of members
in my app's state. Its state contains the members
, each of which has a flag to say whether they're a real member of not. It also contains a flag to keep track of which type of member we're viewing:
this.state = {
viewMembers: true,
members: [
{
id: 1,
name: "Jim",
isMember: true
},
{
id: 2,
name: "John",
isMember: false
}
]
}
In my render
function I map over this array, and only show members corresponding with the view state (i.e. if viewMembers
is true
, I only show members where isMember
is true
, and vice versa). For each member I return a table <tr>
. The map
function is wrapped in a CSSTransitionGroup
tag to fade in the table rows. This all works fine - please see working code here: jsfiddle.net/d9cfh4zg/1/.
My issue is that it currently fades in the new state before fading out the old one, giving it a slightly janky quality. How can I allow existing rows to fade out before fading in the new ones?
try this:
I have added a
refreshState
variable and updated it in thesetTimeout
callback function which is added in thechangeViewState
function.Here is the updated fiddle
hope this helps.