Closed xdc0 closed 4 years ago
Wrapped components can't be referenced directly, since the reference ends up being the connectBackboneToReact and not the wrapped component. Quick example:
connectBackboneToReact
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.
WrappedComponent
connect-backbone-react
this.ref is a connectBackboneToReact object instead a WrappedComponent object.
this.ref
react-redux fixes this by with an option withRef, see here: https://github.com/reduxjs/react-redux/blob/master/docs/api.md#connectadvancedselectorfactory-connectoptions
react-redux
withRef
A similar pattern can allow connect-backbone-to-react to expose the wrapped object reference instead the wrapper itself.
connect-backbone-to-react
Great idea! Pull request for this is most welcome!
This may be good to use the forwardRef API!
This was resolved by #20
Wrapped components can't be referenced directly, since the reference ends up being the
connectBackboneToReact
and not the wrapped component. Quick example:Where
WrappedComponent
is wrapped byconnect-backbone-react
.this.ref
is aconnectBackboneToReact
object instead aWrappedComponent
object.react-redux
fixes this by with an optionwithRef
, see here: https://github.com/reduxjs/react-redux/blob/master/docs/api.md#connectadvancedselectorfactory-connectoptionsA similar pattern can allow
connect-backbone-to-react
to expose the wrapped object reference instead the wrapper itself.