Skip to content

v8.0.0 - forwardRef support

Compare
Choose a tag to compare
@tizmagik tizmagik released this 12 Aug 18:51

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;
            }}
          />
        );
      }
    }