Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asynchronous context change is not propagated to connected components #1479

Closed
zdila opened this issue Mar 5, 2016 · 1 comment
Closed

Comments

@zdila
Copy link

zdila commented Mar 5, 2016

Please see the following example. The only difference between Bar and ConnectedBaz is that the second one uses redux connect.

The problem is that the context changes do not get propagated to the component Baz and it statically renders 0. Cmponent Bar is being updated and re-rendered correctly every second.

import React, {PropTypes} from 'react';
import { connect } from 'react-redux';

class Bar extends React.Component {
  static contextTypes = {
    time: React.PropTypes.number
  };

  render() {
    return <div>{this.context.time}</div>;
  }
}

class Baz extends React.Component {
  static contextTypes = {
    time: React.PropTypes.number
  };

  render() {
    return <div>{this.context.time}</div>;
  }
}

const ConnectedBaz = connect()(Baz);

export default class Foo extends React.Component {
  static childContextTypes = {
    time: React.PropTypes.number
  };

  getChildContext() {
    return {
      time: this.state ? this.state.time : 0
    };
  }

  componentDidMount() {
    setInterval(() => {
      this.setState({time: new Date().getTime()});
    }, 1000);
  }

  render() {
    return <div><Bar/><ConnectedBaz/></div>;
  }
}
@zdila
Copy link
Author

zdila commented Mar 5, 2016

moved to reduxjs/react-redux#311

@zdila zdila closed this as completed Mar 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant