# msteams-react-base-component

> React helper components for Microsoft 365 Teams, Office and Outlook apps

Latest version **4.0.1** (published 2022-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install msteams-react-base-component
pnpm add msteams-react-base-component
yarn add msteams-react-base-component
bun add msteams-react-base-component
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2022-06-28 |
| First published | 2018-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.22.0 |
| Dependencies | 1 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Wictor Wilén |
| Maintainers | wictorwilen |
| Keywords | react, microsoft-teams, msteams, typescript, fluentui, mgt |

## Links

- npm: https://www.npmjs.com/package/msteams-react-base-component
- Repository: https://github.com/wictorwilen/msteams-react-base-component
- Issues: https://github.com/wictorwilen/msteams-react-base-component/issues
- Funding: https://github.com/sponsors/wictorwilen/
- npm.io page: https://npm.io/package/msteams-react-base-component

## Dependencies (1)

- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2022-06-28
- 4.0.1-preview (preview) — 2022-06-28
- 4.0.0 — 2022-06-23
- 4.0.0-preview.7 — 2022-05-18
- 4.0.0-preview.6 — 2022-05-12
- 3.2.0-preview.2 — 2022-02-10
- 3.2.0-preview.1 — 2022-02-09
- 4.0.0-preview5 — 2021-12-13
- 4.0.0-preview4 — 2021-11-16
- 4.0.0-preview3 — 2021-11-15
- 4.0.0-preview2 — 2021-11-15
- 4.0.0-preview — 2021-11-11
- 3.1.1 — 2021-09-30
- 3.1.1-preview — 2021-09-28
- 3.1.0 — 2021-03-01
- … 26 more at https://npm.io/package/msteams-react-base-component/versions

## README

# Microsoft Teams UI Controls base component

[![npm version](https://badge.fury.io/js/msteams-react-base-component.svg)](https://www.npmjs.com/package/msteams-react-base-component)
[![npm](https://img.shields.io/npm/dt/msteams-react-base-component.svg)](https://www.npmjs.com/package/msteams-react-base-component)
[![MIT](https://img.shields.io/npm/l/msteams-react-base-component.svg)](https://github.com/wictorwilen/msteams-react-base-component/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/wictorwilen/msteams-react-base-component.svg)](https://github.com/wictorwilen/msteams-react-base-component/issues)
[![GitHub closed issues](https://img.shields.io/github/issues-closed/wictorwilen/msteams-react-base-component.svg)](https://github.com/wictorwilen/msteams-react-base-component/issues?q=is%3Aissue+is%3Aclosed)

This is a set of React hooks and providers based on the Microsoft Teams JavaScript SDK, the Fluent UI components and Microsoft Graph Toolkit, which is used when generating Microsoft Teams Apps using the [Microsoft Teams Yeoman Generator](https://aka.ms/yoteams).

 | @master | @preview |
 :--------:|:---------:
 ![Build Status](https://img.shields.io/github/workflow/status/wictorwilen/msteams-react-base-component/msteams-react-base-component%20CI/master)|![Build Status](https://img.shields.io/github/workflow/status/wictorwilen/msteams-react-base-component/msteams-react-base-component%20CI/preview)

# Usage

## `useTeams` hook

To use this package in a Teams tab or extension import the `useTeams` Hook and then call it inside a functional component.

``` TypeScript
const [{inTeams}] = useTeams();
```

The `useTeams` hook will return a tuple of where an object of properties are in the first field and an object of methods in the second.

> **NOTE**: using the hook will automatically initialize the Microsoft Teams JS SDK is available.

### useTeams Hook arguments

The `useTeams` hook can take an *optional* object argument:

| Argument | Description |
|----------|-------------|
| `initialTheme?: string` | Manually set the initial theme (`default`, `dark` or `contrast`) |
| `setThemeHandler?: (theme?: string) => void` | Custom handler for themes |

### Available properties

| Property name | Type | Description |
|---------------|------|-------------|
| `inTeams` | boolean? | `true` if hosted in Teams and `false` for outside of Microsoft Teams |
| `fullScreen` | boolean? | `true` if the Tab is in full-screen, otherwise `false` |
| `themeString` | string | The value of `default`, `dark` or `contrast` |
| `theme` | ThemePrepared | The Fluent UI Theme object for the current theme |
| `context` | `Context?` | `undefined` while the Tab is loading or if not hosted in Teams, set to a value once the Tab is initialized and context available |

### Available methods

| Method name | Description |
|-------------|-------------|
| `setTheme(theme?: string)` | Method for manually setting the theme |

## Full example

Example of usage:

```  TypeScript
import * as React from "react";
import { Provider, Flex, Header } from "@fluentui/react-northstar";
import { useState, useEffect } from "react";
import { useTeams } from "msteams-react-base-component";

/**
 * Implementation of the hooks Tab content page
 */
export const HooksTab = () => {
    const [{ inTeams, theme }] = useTeams({});
    const [message, setMessage] = useState("Loading...");

    useEffect(() => {
        if (inTeams === true) {
            setMessage("In Microsoft Teams!");
        } else {
            if (inTeams !== undefined) {
                setMessage("Not in Microsoft Teams");
            }
        }
    }, [inTeams]);

    return (
        <Provider theme={theme}>
            <Flex fill={true}>
                <Flex.Item>
                    <Header content={message} />
                </Flex.Item>
            </Flex>
        </Provider>
    );
};
```

# License

Copyright (c) Wictor Wilén. All rights reserved.

Licensed under the MIT license.

---
_Source: https://npm.io/package/msteams-react-base-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
