File tree Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ <script >
2
+ </script >
Original file line number Diff line number Diff line change
1
+ import type { PageLoad } from "./$types"
2
+
3
+ export const load = ( async ( { params } ) => {
4
+ return {
5
+ title : "useContext" ,
6
+ react : ( await import ( "./react.jsx?raw" ) ) . default ,
7
+ svelte : ( await import ( "./svelte.svelte?raw" ) ) . default ,
8
+ }
9
+ } ) satisfies PageLoad
Original file line number Diff line number Diff line change
1
+ import React , { createContext } from 'react'
2
+ import Toolbar from './Toolbar'
3
+
4
+ const themes = {
5
+ light : {
6
+ foreground : "#000000" ,
7
+ background : "#eeeeee"
8
+ } ,
9
+ dark : {
10
+ foreground : "#ffffff" ,
11
+ background : "#222222"
12
+ }
13
+ }
14
+
15
+ export const ThemeContext = createContext ( themes . light )
16
+
17
+ export default function App ( ) {
18
+ return (
19
+ < ThemeContext . Provider value = { themes . dark } >
20
+ < Toolbar />
21
+ </ ThemeContext . Provider >
22
+ )
23
+ }
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { setContext } from " svelte"
3
+ import Toolbar from " ./Toolbar.svelte"
4
+
5
+ const themes = {
6
+ light: {
7
+ foreground: " #000000" ,
8
+ background: " #eeeeee"
9
+ },
10
+ dark: {
11
+ foreground: " #ffffff" ,
12
+ background: " #222222"
13
+ }
14
+ }
15
+
16
+ setContext (" ThemeContext" , themes .dark )
17
+ </script >
18
+
19
+ <Toolbar />
Original file line number Diff line number Diff line change 13
13
let tile4Url = " /useRef"
14
14
let tile5Url = " /useReducer"
15
15
let tile6Url = " /useCallback"
16
+ let tile7Url = " /useContext"
16
17
</script >
17
18
18
19
<!-- App Shell -->
97
98
href ={tile6Url }
98
99
class ={tile6Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
99
100
>
101
+ <AppRailTile
102
+ label =" useContext"
103
+ title =" useContext"
104
+ value ={6 }
105
+ tag =" a"
106
+ href ={tile7Url }
107
+ class ={tile7Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
108
+ >
100
109
</svelte:fragment >
101
110
102
111
<svelte:fragment slot =" trail" >
You can’t perform that action at this time.
0 commit comments