mirror of https://github.com/sveltejs/svelte
feat: add `createContext` utility for type-safe context (#16948)
* feat: add `createContext` utility for type-safe context * regeneratepull/16946/head
parent
99711d5822
commit
f3c55e8e6c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': minor
|
||||
---
|
||||
|
||||
feat: add `createContext` utility for type-safe context
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { get } from './main.svelte';
|
||||
|
||||
const message = get();
|
||||
</script>
|
||||
|
||||
<h1>{message}</h1>
|
@ -0,0 +1,5 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<h1>hello</h1>`
|
||||
});
|
@ -0,0 +1,16 @@
|
||||
<script module>
|
||||
import { createContext } from 'svelte';
|
||||
|
||||
/** @type {ReturnType<typeof createContext<string>>} */
|
||||
const [get, set] = createContext();
|
||||
|
||||
export { get };
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
set('hello');
|
||||
</script>
|
||||
|
||||
<Child />
|
Loading…
Reference in new issue