Added forwardRef support in #153 thanks to @ParadeTo 🎉 . If you'd like to access the internal ref
of a tracked component, just add the forwardRef option as part of the second param options object:
@track({}, { forwardRef: true })
Technically the API surface has not changed, we just added a new forwardRef: bool
option. But React docs recommend bumping semver major when introducing such a change.
Example:
const focusFn = () => {};
@track({}, { forwardRef: true })
class Child extends React.Component {
focus = focusFn;
render() {
return 'child';
}
}
class Parent extends React.Component {
componentDidMount() {
this.child.focus();
}
render() {
return (
<Child
ref={el => {
this.child = el;
}}
/>
);
}
}