1.0.2 • Published 2 months ago

svelte-create-context v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

NPM Version

svelte-create-context

A keyless and typesafe approach to the Svelte context API

💾 Install

npm i svelte-create-context

⚡ Quick example

// context.ts

import { createContext } from 'svelte-create-context';

export const {
  setup: setupCurrentUser,
  get: getCurrentUser
} = createContext<User>();
// parent component

<script lang="ts">
  import { setupCurrentUser } from './context';

  setupCurrentUser(new User());
</script>
// child component

<script lang="ts">
  import { getCurrentUser } from './context';

  const currentUser = getCurrentUser();
</script>

🔨 API

interface Context<T> {
  setup: (value: T) => void;
  get: () => T;
}

function createContext<T>(): Context<T>
1.0.2

2 months ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago