diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md index 147732911..e4191a37f 100644 --- a/content/docs/error-boundaries.md +++ b/content/docs/error-boundaries.md @@ -1,28 +1,27 @@ --- id: error-boundaries -title: Error Boundaries +title: Xəta Sərhədləri permalink: docs/error-boundaries.html --- -In the past, JavaScript errors inside components used to corrupt React’s internal state and cause it to [emit](https://github.com/facebook/react/issues/4026) [cryptic](https://github.com/facebook/react/issues/6895) [errors](https://github.com/facebook/react/issues/8579) on next renders. These errors were always caused by an earlier error in the application code, but React did not provide a way to handle them gracefully in components, and could not recover from them. +Keçmişdə, komponent daxilində baş verən Javascript xətaları, React-in daxili vəziyyətini korlayıb, sonrakı renderlərdə [kriptik](https://github.com/facebook/react/issues/6895) [xətalar](https://github.com/facebook/react/issues/8579) [göstərirdi](https://github.com/facebook/react/issues/4026). Bu xətaların həmişə applikasiya kodunda əvvəlki xətalara görə baş verməyinə baxmayaraq, React bu xətaların komponent daxilində idarəsi üçün və bu xətalardan bərpa olunmaq üçün heç bir mexanizm təmin etmirdi. +## Xəta Sərhədlərinin Təqdim Edilməsi {#introducing-error-boundaries} -## Introducing Error Boundaries {#introducing-error-boundaries} +UI-ın bir hissəsində baş verən Javascript xətası bütün applikasiyanı sındırmamalıdır. Bu problemin React-də həll olunması üçün, React 16 "xəta sərhədi" adında yeni bir konsepsiya təqdim edir. -A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. +Xəta sərhədləri **uşaq komponent ağacında baş verən Javascript xətaları tutan, bu xətaları qeydiyyata alan və xəta olduqda fallback UI göstərən** bir React komponentidir. Xəta sərhədləri render zamanı, lifecycle metodlarında, və bütün altında olan ağacdakı konstruktorlarda baş verən xətaları tutur. -Error boundaries are React components that **catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI** instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them. - -> Note +> Qeyd > -> Error boundaries do **not** catch errors for: +> Xəta sərhədləri aşağıda baş verən xətaları **tutmur**: > -> * Event handlers ([learn more](#how-about-event-handlers)) -> * Asynchronous code (e.g. `setTimeout` or `requestAnimationFrame` callbacks) -> * Server side rendering -> * Errors thrown in the error boundary itself (rather than its children) +> * Hadisə işləyicilərində ([daha ətraflı](#how-about-event-handlers)) +> * Asinxron kod (məsələn `setTimeout` və ya `requestAnimationFrame` callback-ləri) +> * Serverdə render edilməsi zamanı +> * Xəta sərhədinin daxilində atılan xətalar (uşaqda atılmağın yerinə) -A class component becomes an error boundary if it defines either (or both) of the lifecycle methods [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) or [`componentDidCatch()`](/docs/react-component.html#componentdidcatch). Use `static getDerivedStateFromError()` to render a fallback UI after an error has been thrown. Use `componentDidCatch()` to log error information. +Klass komponenti göstərilən [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) və ya [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) lifecycle metodlarının birini (və ya hər ikisini) tətbiq etdikdə xəta sərhədinə çevrilir. `static getDerivedStateFromError()` funskiyasını xəta atıldıqdan sonra fallback UI render etmək üçün işlədin. `componentDidCatch()` funskiyasını xətaları qeydiyyata almaq üçün işlədin. ```js{7-10,12-15,18-21} class ErrorBoundary extends React.Component { @@ -32,19 +31,19 @@ class ErrorBoundary extends React.Component { } static getDerivedStateFromError(error) { - // Update state so the next render will show the fallback UI. + // Gələn renderdə UI göstərmək üçün state-i yeniləyin. return { hasError: true }; } componentDidCatch(error, info) { - // You can also log the error to an error reporting service + // Siz həmçinin xətaları, xəta hesabat servislərində qeydiyyata ala bilərsiniz logErrorToMyService(error, info); } render() { if (this.state.hasError) { - // You can render any custom fallback UI - return
-
+Siz komponentin stek izində fayl adlarını və sətir nömrələrini də görə bilərsiniz. Bu [Create React App](https://github.com/facebookincubator/create-react-app) layihələrində birbaşa işləyir:
-You can also see the filenames and line numbers in the component stack trace. This works by default in [Create React App](https://github.com/facebookincubator/create-react-app) projects:
+
-
+Əgər siz Create React App istifadə etmirsinizsə, siz [bu plugini](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) əllə Babel konfiqurasiyasına əlavə edə bilərsiniz. Qeyd edək ki, bu yalnız development zamanı işlətmək üçündür və **production-də söndürülməlidir**.
-If you don’t use Create React App, you can add [this plugin](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) manually to your Babel configuration. Note that it’s intended only for development and **must be disabled in production**.
-
-> Note
+> Qeyd
>
-> Component names displayed in the stack traces depend on the [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property. If you support older browsers and devices which may not yet provide this natively (e.g. IE 11), consider including a `Function.name` polyfill in your bundled application, such as [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name). Alternatively, you may explicitly set the [`displayName`](/docs/react-component.html#displayname) property on all your components.
-
+> Komponent adları stek izlərində [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) parametrindən asılıdır. Əgər siz bu parametri nativ formada dəstəkləməyən köhnə brauzerləri və cihazları dəstəkləyirsinizsə (məsələn IE 11), `Function.name` polifilini (məsələn [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name)) paketlənmiş applikasiyanıza əlavə edin. Alternativ olaraq, siz açıq şəkildə `displayName` parametrini bütün komponentlərdə təyin edə bilərsiniz.
-## How About try/catch? {#how-about-trycatch}
+## Bəs try/catch? {#how-about-trycatch}
-`try` / `catch` is great but it only works for imperative code:
+`try` / `catch` əladır amma yalnız imperativ kod ilə işləyir:
```js
try {
@@ -116,21 +112,21 @@ try {
}
```
-However, React components are declarative and specify *what* should be rendered:
+Lakin, React komponentlər deklarativdirlər və **nəyin** render olunacağını müəyyənləşdirirlər:
```js
```
-Error boundaries preserve the declarative nature of React, and behave as you would expect. For example, even if an error occurs in a `componentDidUpdate` method caused by a `setState` somewhere deep in the tree, it will still correctly propagate to the closest error boundary.
+Xəta sərhərləri React-in deklarativ təbiətini saxlayır və sizin gözlədiyiniz kimi davranırlar. Məsələn, əgər xəta, ağacın dərinliyində olan komponentin `componentDidUpdate` funskiyasında `setState`-ə görə baş versə belə, React yenədə xətanı ən yaxın xəta sərhədinə yayacaq.
-## How About Event Handlers? {#how-about-event-handlers}
+## Bəs Hadisə İşləyiciləri? {#how-about-event-handlers}
-Error boundaries **do not** catch errors inside event handlers.
+Xəta sərhədləri hadisə işləyicilərində baş verən xətaları **tutmur**.
-React doesn't need error boundaries to recover from errors in event handlers. Unlike the render method and lifecycle methods, the event handlers don't happen during rendering. So if they throw, React still knows what to display on the screen.
+React-ə hadisə işləyicilərində baş verən xətaların bərpası üçün, xəta sərhədlərindən istifadə etməsi lazım deyil. Render və lifecycle metodlarından fərqli olaraq, hadisə işləyiciləri render zamanı baş vermir. Bu səbəbdən, əgər bu işləyicilər xəta atırlarsa, React yenə də ekranda nə göstərəcəyini bilir.
-If you need to catch an error inside event handler, use the regular JavaScript `try` / `catch` statement:
+Əgər sizə hadisə işləyicilərində yeni xətanı tutmaq lazımdırsa, normal Jacascript `try` / `catch` ifadəsindən istifadə edin:
```js{9-13,17-20}
class MyComponent extends React.Component {
@@ -142,7 +138,7 @@ class MyComponent extends React.Component {
handleClick() {
try {
- // Do something that could throw
+ // Xəta atması üçün nəsə edin
} catch (error) {
this.setState({ error });
}
@@ -150,17 +146,17 @@ class MyComponent extends React.Component {
render() {
if (this.state.error) {
- return