# vue-context-api

> A react-like context api for Vue

Latest version **1.0.1** (published 2018-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-context-api
pnpm add vue-context-api
yarn add vue-context-api
bun add vue-context-api
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-05-22 |
| First published | 2018-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | zephraph |
| Maintainers | zephraph |
| Keywords | vue, react, context, api, provider, consumer, inject, provide |

## Links

- npm: https://www.npmjs.com/package/vue-context-api
- Repository: https://github.com/zephraph/vue-context-api
- Homepage: https://github.com/zephraph/vue-context-api#readme
- Issues: https://github.com/zephraph/vue-context-api/issues
- npm.io page: https://npm.io/package/vue-context-api

## 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

- 1.0.1 (latest) — 2018-05-22
- 1.0.0 — 2018-05-22

## README

# vue-context-api

A react-like context component api for Vue.js

## Installation

```
npm install --save vue-context-api
```

or

```
yarn add vue-context-api
```

## Example Usage

See a [live example](https://codesandbox.io/s/nrjz7ky4mp).

** ThemeContext.js **

```javascript
import { createContext } from "vue-context-api";

// The argument passed to createContext is the default context value
export const { Provider, Consumer } = createContext("light");
```

** App.vue **

```html
<template>
  <!-- value can be reactive. Overrides the default value passed into createContext -->
  <ThemeProvider value="dark">
    <ThemedButton/>
  </ThemeProvider>
</template>

<script>
import ThemedButton from "./ThemedButton";
import { Provider as ThemeProvider } from "./ThemeContext";

export default {
  components: {
    ThemedButton,
    ThemeProvider
  }
};
</script>
```

** ThemedButton.vue **

```html
<template>
  <ThemeConsumer>
    <button slot-scope="theme" :style="setTheme(theme)"/>
  </ThemeConsumer>
</template>

<script>
import { Consumer as ThemeConsumer } from "./ThemeContext";

export default {
  components: {
    ThemeConsumer
  },
  methods: {
    setTheme(theme) {
      return theme === 'light'
        ? 'background-color: white'
        : 'background-color: black'
    }
  }
}
</script>
```

---
_Source: https://npm.io/package/vue-context-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
