I think one way you could do this is to add a property to the GanttLayout which is a go.Diagram.
Then you would set that property in a componentDidMount/useEffect, after both refs are valid. You can get the Diagram from a ref by calling this.myTasksRef.current?.getDiagram();.