You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/svelte/06-runtime/02-context.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ NOTE: do not edit this file, it is generated in apps/svelte.dev/scripts/sync-doc
3
3
title: Context
4
4
---
5
5
6
-
Context allows components to access values owned by parent components without passing them down as props (potentially through many layers of intermediate components, known as 'prop-drilling'). The parent component sets context with `setContext(key, value)`...
@@ -14,7 +14,7 @@ Context allows components to access values owned by parent components without pa
14
14
</script>
15
15
```
16
16
17
-
...and the child retrieves it with `getContext`:
17
+
...そして、子コンポーネントは `getContext` で context を取得します:
18
18
19
19
```svelte
20
20
<!--- file: Child.svelte --->
@@ -27,21 +27,21 @@ Context allows components to access values owned by parent components without pa
27
27
<h1>{message}, inside Child.svelte</h1>
28
28
```
29
29
30
-
This is particularly useful when `Parent.svelte`is not directly aware of `Child.svelte`, but instead renders it as part of a `children`[snippet](snippet)([demo](/playground/untitled#H4sIAAAAAAAAE42Q3W6DMAyFX8WyJgESK-oto6hTX2D3YxcM3IIUQpR40yqUd58CrCXsp7tL7HNsf2dAWXaEKR56yfTBGOOxFWQwfR6Qz8q1XAHjL-GjUhvzToJd7bU09FO9ctMkG0wxM5VuFeeFLLjtVK8ZnkpNkuGo-w6CTTJ9Z3PwsBAemlbUF934W8iy5DpaZtOUcU02-ZLcaS51jHEkTFm_kY1_wfOO8QnXrb8hBzDEc6pgZ4gFoyz4KgiD7nxfTe8ghqAhIfrJ46cTzVZBbkPlODVJsLCDO6V7ZcJoncyw1yRr0hd1GNn_ZbEM3I9i1bmVxOlWElUvDUNHxpQngt3C4CXzjS1rtvkw22wMrTRtTbC8Lkuabe7jvthPPe3DofYCAAA=)):
In addition to [`setContext`](svelte#setContext)and[`getContext`](svelte#getContext), Svelte exposes[`hasContext`](svelte#hasContext)and[`getAllContexts`](svelte#getAllContexts)functions.
## state と context を使用する <!--Using-context-with-state-->
43
43
44
-
You can store reactive state in context ([demo](/playground/untitled#H4sIAAAAAAAAE41R0W6DMAz8FSuaBNUQdK8MkKZ-wh7HHihzu6hgosRMm1D-fUpSVNq12x4iEvvOx_kmQU2PIhfP3DCCJGgHYvxkkYid7NCI_GUS_KUcxhVEMjOelErNB3bsatvG4LW6n0ZsRC4K02qpuKqpZtmrQTNMYJA3QRAs7PTQQxS40eMCt3mX3duxnWb-lS5h7nTI0A4jMWoo4c44P_Hku-zrOazdy64chWo-ScfRkRgl8wgHKrLTH1OxHZkHgoHaTraHcopXUFYzPPVfuC_hwQaD1GrskdiNCdQwJljJqlvXfyqVsA5CGg0uRUQifHw56xFtciO75QrP07vo_JXf_tf8yK2ezDKY_ZWt_1y2qqYzv7bI1IW1V_sN19m-07wCAAA=))...
44
+
リアクティブな state を context に保存できます ([デモ](/playground/untitled#H4sIAAAAAAAAE41R0W6DMAz8FSuaBNUQdK8MkKZ-wh7HHihzu6hgosRMm1D-fUpSVNq12x4iEvvOx_kmQU2PIhfP3DCCJGgHYvxkkYid7NCI_GUS_KUcxhVEMjOelErNB3bsatvG4LW6n0ZsRC4K02qpuKqpZtmrQTNMYJA3QRAs7PTQQxS40eMCt3mX3duxnWb-lS5h7nTI0A4jMWoo4c44P_Hku-zrOazdy64chWo-ScfRkRgl8wgHKrLTH1OxHZkHgoHaTraHcopXUFYzPPVfuC_hwQaD1GrskdiNCdQwJljJqlvXfyqVsA5CGg0uRUQifHw56xFtciO75QrP07vo_JXf_tf8yK2ezDKY_ZWt_1y2qqYzv7bI1IW1V_sN19m-07wCAAA=))...
45
45
46
46
```svelte
47
47
<script>
@@ -64,27 +64,27 @@ You can store reactive state in context ([demo](/playground/untitled#H4sIAAAAAAA
64
64
<Child />
65
65
```
66
66
67
-
...though note that if you _reassign_`counter`instead of updating it, you will 'break the link' — in other words instead of this...
In many cases this is perfectly fine, but there is a risk: if you mutate the state during server-side rendering (which is discouraged, but entirely possible!)...
124
+
大部分のケースではまったく問題ありませんが、リスクがあります。サーバーサイドレンダリング中に state を変更すると(これは非推奨ですが、完全に可能です!)...
125
125
126
126
```svelte
127
127
<!--- file: App.svelte ---->
@@ -136,4 +136,4 @@ In many cases this is perfectly fine, but there is a risk: if you mutate the sta
136
136
</script>
137
137
```
138
138
139
-
...then the data may be accessible by the _next_ user. Context solves this problem because it is not shared between requests.
0 commit comments