[10.0.0-rc1] Really weird issue with react-redux connect()
See original GitHub issueSo I’m running slightly newer than -rc1 based on the git from ~18h ago. Running with a particular route under react-router-dom with a route like /foo/:id
I have a relatively simple component which is connected to the store with react-redux and toggles between null
and a sub-component view based on the value from the store - in test case below the string foo
. When the id value changes a different prop (song
) is passed to the subcomponent. The bug is that when the component is showing on a page and the store changes to make render()
return null, the component hides correctly. But when I navigate to a new id (ie doesnt unmount, but props change) the component is rendered in its old form even though render()
is still called and returns null.
If I switch away from using the connect()
function to directly subscribing and changing component state based on the store value then the component behaves correctly. Switching to react 16.9.0 also does not display this issue.
Smallest case I can reproduce with in my app (ie inside the routing) is below. This is the one that doesn’t work:
class _PresenterView extends Component {
render() {
const { song, is_active } = this.props;
if( !is_active )
return null;
return 'foo';
}
}
export const PresenterView = connect(state => ({ is_active: state.cast.active }))(_PresenterView);
And if we connect manually to the store then this works correctly:
export class PresenterView extends Component {
componentDidMount() {
store.subscribe(() => this.setState({ is_active: store.getState().cast.active }));
}
render() {
const { is_active } = this.state;
const { song } = this.props;
if( !is_active )
return null;
return 'foo';
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (11 by maintainers)
Top GitHub Comments
What versions are you running from the sub-libraries, it would probably help to make a minimal codesandbox. This ensures that we aren’t looking at an issue with another library introducing an issue.
Codesandbox simplifies checking if it works with an earlier version as well.
This should be fixed in the stable version