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

anu版本1.1.4 context无效的bug #71

Closed
Foveluy opened this issue Oct 25, 2017 · 2 comments
Closed

anu版本1.1.4 context无效的bug #71

Foveluy opened this issue Oct 25, 2017 · 2 comments

Comments

@Foveluy
Copy link

Foveluy commented Oct 25, 2017

import React from 'anujs';
import ReactDOM from 'anujs';
import PropTypes from 'anujs';

class Parent extends React.Component {
  render() {
    return (<div className="parent"><Son /></div>)
  }
}
class Son extends React.Component {
  render() {
    return (<div className="son">{this.context.value}</div>)
  }
}
class App extends React.Component {
  getChildContext() {
    return {
      value: 666
    };
  }
  render() {
    return (<div className='app'><Parent /></div>)
  }
};
ReactDOM.render(
  <App/>,
  document.getElementById('root')
)

在上述代码中,无法获取到{this.context.value}

代码出处:https://rubylouvre.github.io/anu/context.html

@Foveluy
Copy link
Author

Foveluy commented Oct 25, 2017

2017-10-25 10 21 46

代码运行截图

@RubyLouvre
Copy link
Owner

改了,为了与官方保持一致。

class Parent extends React.Component {
            render() {
                return (
                    <div className="parent">
                        <Son />
                    </div>
                );
            }
        }
        class Son extends React.Component {
            static contextTypes = {
                value: React.PropTypes.number
            };
            render() {
                return <div className="son">{this.context.value}</div>;
            }
        }
        class App extends React.Component {
            static childContextTypes = {
                value: React.PropTypes.number
            };
            getChildContext() {
                return {
                    value: 666
                };
            }
            render() {
                return (
                    <div className="app">
                        <Parent />
                    </div>
                );
            }
        }
        var div = document.createElement("div")
        ReactDOM.render(<App />, div);
        expect(div.textContent || div.innerText).toBe("666")

@Foveluy Foveluy closed this as completed Oct 29, 2017
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

2 participants