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

React Ref #63

Open
hushicai opened this issue Jun 14, 2019 · 2 comments
Open

React Ref #63

hushicai opened this issue Jun 14, 2019 · 2 comments

Comments

@hushicai
Copy link
Owner

hushicai commented Jun 14, 2019

React Ref的发展历程:

facebook/react#1373

@hushicai
Copy link
Owner Author

@hushicai
Copy link
Owner Author

hushicai commented Jun 14, 2019

string ref

string ref无法绑定到当前的"所有者":

class Child extends React.Component {
  componentDidMount() {
   // `test` ref is here
    console.log("child", this.refs);
  }
  render() {
    let { renderer } = this.props;

    return renderer && renderer();
  }
}

class Parent extends React.Component {
  componentDidMount() {
   // empty object
    console.log("parent", this.refs);
  }
  render() {
    return (
      <Child
        renderer={() => {
          // ref属于调用者`Child`,而不是当前的`Parent`
          return <input ref="test" placeholder="ref test" />;
        }}
      />
    );
  }
}

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