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
Call `createContext` outside of any components to create a context.
23
+
Bir context oluşturmak için bileşenlerin dışından `createContext`'i çağırın.
24
24
25
25
```js
26
26
import { createContext } from'react';
27
27
28
28
constThemeContext=createContext('light');
29
29
```
30
30
31
-
[See more examples below.](#usage)
31
+
[Daha fazla örnek için aşağıya bakınız.](#usage)
32
32
33
-
#### Parameters {/*parameters*/}
33
+
#### Parametreler {/*parameters*/}
34
34
35
-
*`defaultValue`: The value that you want the context to have when there is no matching context provider in the tree above the component that reads context. If you don't have any meaningful default value, specify `null`. The default value is meant as a "last resort" fallback. It is static and never changes over time.
35
+
*`defaultValue`: Context'i okuyan bileşenlerin üzerinde eşleşen bir context sağlayıcısı olmadığında contextin sahip olmasını istediğiniz değer. Anlamlı bir varsayılan değeriniz yoksa, `null` belirtin. Varsayılan değer, "son çare" olarak başvurulacak bir alternatif olarak düşünülür. Statiktir ve zamanla asla değişmez.
36
36
37
-
#### Returns {/*returns*/}
37
+
#### Geri Dönüş Değeri {/*returns*/}
38
38
39
-
`createContext`returns a context object.
39
+
`createContext`bir context nesnesi döndürür.
40
40
41
-
**The context object itself does not hold any information.**It represents _which_ context other components read or provide. Typically, you will use [`SomeContext.Provider`](#provider)in components above to specify the context value, and call [`useContext(SomeContext)`](/reference/react/useContext)in components below to read it. The context object has a few properties:
41
+
**Context nesnesinin kendisi herhangi bir bilgi içermez.**Diğer bileşenlerin _hangi_ contexti okuyacağını veya sağlayacağını temsil eder. Genellikle, context değerini belirtmek için bileşenin üstünde [SomeContext.Provider](https://react.dev/reference/react/createContext#provider)kullanır ve bileşenin altında okumak için [useContext(SomeContext)](https://react.dev/reference/react/useContext)çağırırsınız. Context nesnesinin birkaç özelliği vardır:
42
42
43
-
*`SomeContext.Provider`lets you provide the context value to components.
44
-
*`SomeContext.Consumer`is an alternative and rarely used way to read the context value.
43
+
*`SomeContext.Provider`bilenşenlerin context değerini sağlamanıza olanak tanır.
44
+
*`SomeContext.Consumer`context değerini okumak için nadiren kullanılan alternatif bir yöntemdir.
45
45
46
46
---
47
47
48
48
### `SomeContext.Provider` {/*provider*/}
49
49
50
-
Wrap your components into a context provider to specify the value of this context for all components inside:
50
+
Bileşenlerinizi bir context sağlayıcısı ile sarmalayarak içindeki tüm bileşenler için bu contextin değerini belirtin:
51
51
52
52
```js
53
53
functionApp() {
@@ -63,17 +63,18 @@ function App() {
63
63
64
64
#### Props {/*provider-props*/}
65
65
66
-
*`value`: The value that you want to pass to all the components reading this context inside this provider, no matter how deep. The context value can be of any type. A component calling [`useContext(SomeContext)`](/reference/react/useContext) inside of the provider receives the `value` of the innermost corresponding context provider above it.
66
+
*`value`: Ne kadar derin olursa olsun, bu sağlayıcının içindeki contexti okuyan tüm bileşenlere aktarmak istediğiniz değer. Context değeri herhangi bir türde olabilir. Sağlayıcı içinde [`useContext(SomeContext)`](/reference/react/useContext) kullanan bir bileşen,
67
+
üzerindeki en içte bulunan ilgili context sağlayıcısının `value` değerini alır.
67
68
68
69
---
69
70
70
71
### `SomeContext.Consumer` {/*consumer*/}
71
72
72
-
Before `useContext`existed, there was an older way to read context:
73
+
`useContext`var olmadan önce, contexti okumak için daha eski bir yol vardı:
73
74
74
75
```js
75
76
functionButton() {
76
-
// 🟡 Legacy way (not recommended)
77
+
// 🟡 Eski yöntem (önerilmez)
77
78
return (
78
79
<ThemeContext.Consumer>
79
80
{theme=> (
@@ -84,29 +85,29 @@ function Button() {
84
85
}
85
86
```
86
87
87
-
Although this older way still works, but **newly written code should read context with [`useContext()`](/reference/react/useContext)instead:**
88
+
Bu eski yöntem hala çalışıyor olsa da, **yeni yazılan kodun contextini [`useContext()`](/reference/react/useContext)ile okumak daha uygundur:**
88
89
89
90
```js
90
91
functionButton() {
91
-
// ✅ Recommended way
92
+
// ✅ Önerilen yöntem
92
93
consttheme=useContext(ThemeContext);
93
94
return<button className={theme} />;
94
95
}
95
96
```
96
97
97
98
#### Props {/*consumer-props*/}
98
99
99
-
*`children`: A function. React will call the function you pass with the current context value determined by the same algorithm as [`useContext()`](/reference/react/useContext)does, and render the result you return from this function. React will also re-run this function and update the UI whenever the context from the parent components changes.
100
+
*`children`: Bir fonksiyon. React, üst bileşenlerden gelen contextin güncel değerini [`useContext()`](/reference/react/useContext)ile aynı algoritmayı kullanarak belirleyecek ve bu fonksiyondan döndürdüğünüz sonucu render edecektir. Üst bileşenlerden gelen context değiştiğinde, React bu fonksiyonu tekrar çalıştırır ve UI'yi günceller.
100
101
101
102
---
102
103
103
-
## Usage {/*usage*/}
104
+
## Kullanım {/*usage*/}
104
105
105
-
### Creating context {/*creating-context*/}
106
+
### Context oluşturma {/*creating-context*/}
106
107
107
-
Context lets components [pass information deep down](/learn/passing-data-deeply-with-context)without explicitly passing props.
108
+
Context, bileşenlerin [bilgiyi derinlemesine aktarmasına](/learn/passing-data-deeply-with-context)olanak tanır ve açıkça propları geçirmeden yapar.
108
109
109
-
Call `createContext` outside any components to create one or more contexts.
110
+
Bir veya birden fazla context oluşturmak için bileşenlerin dışında `createContext`'i çağırın.
`createContext`returns a <CodeStepstep={1}>context object</CodeStep>. Components can read context by passing it to [`useContext()`](/reference/react/useContext):
By default, the values they receive will be the <CodeStepstep={3}>default values</CodeStep> you have specified when creating the contexts. However, by itself this isn't useful because the default values never change.
133
+
Varsayılan olarak, aldıkları değerler contexti oluştururken belirttiğiniz <CodeStepstep={3}>varsayılan değerler</CodeStep> olacaktır. Ancak, varsayılan değerlerin hiçbiri zamanla değişmediği için bu tek başına yararlı değildir.
133
134
134
-
Context is useful because you can **provide other, dynamic values from your components:**
135
+
Context, **bileşenlerinizden diğer dinamik değerleri sağlayabileceğiniz** için kullanışlıdır:
135
136
136
137
```js {8-9,11-12}
137
138
functionApp() {
@@ -150,15 +151,16 @@ function App() {
150
151
}
151
152
```
152
153
153
-
Now the `Page`component and any components inside it, no matter how deep, will "see" the passed context values. If the passed context values change, React will re-render the components reading the context as well.
154
+
Şimdi `Page`bileşeni ve içindeki herhangi bir bileşen, ne kadar derin olursa olsun, iletilen context değerlerini "görecek" ve iletilen context değerleri değişirse, React contexti okuyan bileşenleri yeniden render edecektir.
154
155
155
-
[Read more about reading and providing context and see examples.](/reference/react/useContext)
156
+
[Okuma ve sağlama contexti hakkında daha fazla bilgi edinin ve örnekleri görün.](/reference/react/useContext)
156
157
157
158
---
158
159
159
-
### Importing and exporting context from a file {/*importing-and-exporting-context-from-a-file*/}
160
+
### Contexti bir dosyadan içe ve dışa aktarma {/*importing-and-exporting-context-from-a-file*/}
160
161
161
-
Often, components in different files will need access to the same context. This is why it's common to declare contexts in a separate file. Then you can use the [`export` statement](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export) to make context available for other files:
162
+
163
+
Çoğu zaman, farklı dosyalardaki bileşenlerin aynı contexte erişmesi gerekecektir. Bu nedenle, contextleri ayrı bir dosyada oluşturmak yaygındır. Ardından, diğer dosyalar için contexti kullanılabilir kılmak için [export ifadesini](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export) kullanabilirsiniz:
Components declared in other files can then use the [`import`](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/import) statement to read or provide this context:
173
+
Diğer dosyalarda tanımlanan bileşenler, bu contexti okumak veya sağlamak için[`import`](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/import) ifadesini kullanabilir:
172
174
173
175
```js {2}
174
176
// Button.js
@@ -196,22 +198,22 @@ function App() {
196
198
}
197
199
```
198
200
199
-
This works similar to [importing and exporting components.](/learn/importing-and-exporting-components)
201
+
Bu, [bileşenleri içe ve dışa aktarma.](/learn/importing-and-exporting-components) işlemine benzer şekilde çalışır.
200
202
201
203
---
202
204
203
-
## Troubleshooting {/*troubleshooting*/}
205
+
## Sorun Giderme {/*troubleshooting*/}
204
206
205
-
### I can't find a way to change the context value {/*i-cant-find-a-way-to-change-the-context-value*/}
207
+
### Context değerini değiştirmenin bir yolunu bulamıyorum {/*i-cant-find-a-way-to-change-the-context-value*/}
206
208
207
209
208
-
Code like this specifies the *default* context value:
210
+
Böyle bir kod, *varsayılan* context değerini belirtir:
209
211
210
212
```js
211
213
const ThemeContext = createContext('light');
212
214
```
213
215
214
-
This value never changes. React only uses this value as a fallback if it can't find a matching provider above.
216
+
Bu değer asla değişmez. React, yalnızca eşleşen bir sağlayıcı bulamazsa bu değeri bir geri dönüş olarak kullanır.
215
217
216
-
To make context change over time, [add state and wrap components in a context provider.](/reference/react/useContext#updating-data-passed-via-context)
218
+
Contextin zaman içinde değişmesini sağlamak için, [state ekleyin ve bileşenleri context sağlayıcısıyla sarın.](/reference/react/useContext#updating-data-passed-via-context)
0 commit comments