I'm working on a bigger project but I created this short example to illustrate the problem.
If I use Box
component, its works. It outputs in the console componentWillEnter
and
componentWillLeave
when we click on the button.
If I use BoxContainer
container, it doesn't work anymore. componentWillEnter
and componentWillLeave
special lifecycle hooks are not called.
{this.state.shouldShowBox && <BoxContainer/>}
Webpack build is done correctly, no errors in the console, but It outputs nothing.
I also tried with high-level API :ReactCSSTransitionGroup
, and it works with Box
and BoxContainer
component. But I need to use the low-level API : ReactTransitionGroup
.
Do you have an idea why it doesn't works when we use react-redux
?
Version used :
- react : 15.0.2
- redux : 3.5.2
- react-redux : 4.4.5
Code :
import React from 'react';
import {render} from 'react-dom';
import {Provider, connect} from 'react-redux';
import {createStore, compose, combineReducers} from 'redux';
import TransitionGroup from 'react/lib/ReactTransitionGroup';
// Box component
class Box extends React.Component {
componentWillEnter(callback) {
console.log('componentWillEnter');
callback();
}
componentWillLeave(callback) {
console.log('componentWillLeave');
callback();
}
render() {
return <div className="box"/>;
}
}
// Boxe connected component
const BoxContainer = connect(null, {})(Box);
// App component
class App extends React.Component {
state = {
shouldShowBox: true
};
toggleBox = () => {
this.setState({
shouldShowBox: !this.state.shouldShowBox
});
};
render() {
return (
<div>
<TransitionGroup>
{this.state.shouldShowBox && <BoxContainer/>}
</TransitionGroup>
<button className="toggle-btn" onClick={this.toggleBox}>
toggle
</button>
</div>
);
}
}
// reducer
function reducer(state = [], action) {
switch (action.type) {
default:
return state
}
}
// store
const store = createStore(reducer);
// render
render(
<Provider store={store}>
<App />
</Provider>
,
document.getElementById('root')
);