在 Azure DevOps 扩展中在哪里调用 SDK.init()? componentWillMout() 将被弃用

Where to call SDK.init() in Azure DevOps extension? componentWillMout() will be deprecated

在许多 Azure DevOps 扩展示例中,componentWillMount() 中有对 SDK.init() 的调用。

例如here:

public async componentWillMount() {
    SDK.init();
    const repoSvc = await SDK.getService<IVersionControlRepositoryService>(GitServiceIds.VersionControlRepositoryService);
}

但是 componentWillMount()deprecated now。那么我应该把这段代码放在哪里呢?

注意:我在这个例子中调用SDK.init()时也遗漏了await。我想它应该在那里。

研究一些现有的插件后,有一个比将 SDK.init() 移动到 componentDidMount 更好的方法:

我找到了初始化 in this plugin from Microsoft 的最佳方法。只需将 SDK.init() 放入您的 app.ts

import * as SDK from "azure-devops-extension-sdk";

SDK.init();