mongodb-js / connect-backbone-to-react

Connect Backbone Models and Collections to React.
https://www.npmjs.com/package/connect-backbone-to-react
Apache License 2.0
27 stars 5 forks source link

Wrapped components cannot be referenced via parent components. #18

Closed xdc0 closed 4 years ago

xdc0 commented 6 years ago

Wrapped components can't be referenced directly, since the reference ends up being the connectBackboneToReact and not the wrapped component. Quick example:

class MyComponent extends Component {
  constructor() {
    super();
    this.ref = null;
  }

  render() {
    return (<WrappedComponent ref={(ref) => this.ref = ref}/>);
  }
}

Where WrappedComponent is wrapped by connect-backbone-react.

this.ref is a connectBackboneToReact object instead a WrappedComponent object.

react-redux fixes this by with an option withRef, see here: https://github.com/reduxjs/react-redux/blob/master/docs/api.md#connectadvancedselectorfactory-connectoptions

A similar pattern can allow connect-backbone-to-react to expose the wrapped object reference instead the wrapper itself.

hswolff commented 6 years ago

Great idea! Pull request for this is most welcome!

hswolff commented 5 years ago

This may be good to use the forwardRef API!

jetpacmonkey commented 4 years ago

This was resolved by #20