Instance Methods

Additional methods are available on timeline objects when you have a reference to an instance of a timeline. Refs provide a way to access React elements created in the render method. For example, when you have a ref to a timeline, you can call the fit method which will adjust the view to make all timeline items visible. See the API Reference for more details.

For information about giving your test framework access to your timeline, see Useful Instance Methods.

Creating a ref in a stateful component

This example uses the React.createRef() API, introduced in React 16.3. If you are using an earlier release of React we recommend using callback refs instead.

class MyStatefulComponent extends React.PureComponent {
  constructor(props) {
    super(props);
    this.timeline = React.createRef();
  }

  fitToView = () => {
    this.timeline.current.fit();
  };

  render = () => {
    const { items } = this.props;
    return (
      <>
        <Timeline ref={this.timeline} items={items} />
        <button onClick={this.fitToView}>
          Show all items
        </button>
      </>
    );
  };
}

Creating a ref in a functional component

If you are using React 16.8 or above then you have access to the hooks API and can use the useRef() hook in your functional components.

const MyFunctionalComponent = (props) => {
  const { items } = props;
  const timelineRef = React.useRef(null);

  const fitToView = () => {
    timelineRef.current.fit();
  };

  return (
    <>
      <Timeline ref={timelineRef} items={items} />
      <button onClick={fitToView}>
        Show all items
      </button>
    </>
  );
};

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.