Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useTeams is returning old context model #435

Open
vatsal121 opened this issue Jul 5, 2022 · 1 comment
Open

useTeams is returning old context model #435

vatsal121 opened this issue Jul 5, 2022 · 1 comment
Assignees

Comments

@vatsal121
Copy link
Contributor

I cloned the "hello-world-tab-without-sso" project from the "dev" branch. I have upgraded the app to V2 SDK.

I am using the useTeams function from the "msteams-react-base-component" package and it is returning the old context object structure instead of new context structure that is updated in teams sdk V2. I am using @microsoft/teams-js: "^2.0.0" in my app.

When I use the below pattern, it returns old structure from V1 sdk as well as in some cases the context object is returned null.
Example:
`
import { useTeams } from "msteams-react-base-component";
export default function App() {
const { context } = useTeams({})[0];

useEffect(() => {

// Returns old context model
console.log(context);
}, [context])

return (
<>Demo app</>
);
}
`

But when I use the app.getContext(), it returns the new structure as well as work perfectly every time.
`
import { app } from "@microsoft/teams-js";
import { ReactElement, useEffect, useState } from "react";

export default function App(): ReactElement {
const [context, setContext] = useState({} as app.Context);

useEffect(() => {
if (!app.isInitialized()) {
app.initialize();
}
app.getContext().then((context) => {
setContext(context);
console.log(context);
}).catch((err) => {
console.error("Error getting context -> ", err);
});

}, []);

return (
<>Demo app</>
);

}
`

I do not see any update this package "msteams-react-base-component".

@sffamily
Copy link
Contributor

sffamily commented Oct 8, 2022

@vatsal121 it is related with the SDK versions and we have some comments in this issue: OfficeDev/TeamsFx#6082 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants