@tramvai/react 1.60.1 → 1.62.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +20 -15
  2. package/package.json +2 -2
  3. package/README.en.md +0 -109
package/README.md CHANGED
@@ -1,8 +1,13 @@
1
+ ---
2
+ title: '@tramvai/react'
3
+ sidebar_position: 2
4
+ ---
5
+
1
6
  # React
2
7
 
3
- `@tramvai/react` - библиотека для интеграции возможностей `tramvai` с `React` компонентами
8
+ `@tramvai/react` - library for integrating tramvai features with `React` components
4
9
 
5
- ## Подключение в проекте
10
+ ## Install
6
11
 
7
12
  ```bash
8
13
  npm i --save @tramvai/react
@@ -10,7 +15,7 @@ npm i --save @tramvai/react
10
15
 
11
16
  ## DI
12
17
 
13
- При создание компонентов вам может понадобиться получение данных с di для этого есть hook `useDi` и HoC `withDi`
18
+ When creating components, you may need to get data from di, for this there is a hook `useDi` and HoC `withDi`
14
19
 
15
20
  ### useDi
16
21
 
@@ -22,15 +27,15 @@ type useDi = (deps: Record<string, string | Token>) => Record<string, any>;
22
27
  type useDi = (dep: string | Token) => any;
23
28
  ```
24
29
 
25
- Хук в который мы можем передать как объект с требуемыми зависимостями и нам вернется объект с данными, так и единичный token, где нам вернется результат. При вызове `useDi` мы получаем данные из di и если мы не нашли данных в di, произойдет ошибка.
30
+ A hook into which we can pass both an object with the required dependencies and an object with data will be returned to us, as well as a single token, where the result will be returned to us. When we call `useDi`, we get data from di and if we don't find data in di, an error will occur.
26
31
 
27
32
  ```javascript
28
33
  import React from 'react';
29
34
  import { useDi } from '@tramvai/react';
30
35
 
31
36
  const MyComponent = () => {
32
- const { logger } = useDi({ logger: 'logger' }); // передаем объект
33
- const Region = useDi(regionToken); // передаем единичный токен
37
+ const { logger } = useDi({ logger: 'logger' }); // pass the object
38
+ const Region = useDi(regionToken); // pass a single token
34
39
 
35
40
  logger.info('text');
36
41
 
@@ -51,7 +56,7 @@ type withDi = (
51
56
  ) => (wrapper: React.ReactElement<any>) => React.ReactElement<any>;
52
57
  ```
53
58
 
54
- Хок, который позволяет обернуть любые компоненты, получить данные из `DI` и передать результат с зависимостями в props компонента
59
+ A HoC that allows you to wrap any components, get data from `DI` and pass the result with dependencies to the props of the component
55
60
 
56
61
  ```javascript
57
62
  import React from 'react';
@@ -72,31 +77,31 @@ class BoxyPage extends Component {
72
77
  type useDiContainer = () => DI.Container;
73
78
  ```
74
79
 
75
- Получение инстанса DI контейнера который был добавлен в контекст приложения.
80
+ Getting an instance of a DI container that has been added to the application context.
76
81
 
77
- Лучше не пользоваться этим hook, так как он сильно низкоуровневый и предназначен для разработки новых hook
82
+ It is better not to use this hook, as it is very low-level and is intended for developing new hooks
78
83
 
79
84
  ## Error
80
85
 
81
- Для обработки ошибок при рендере в React используются [Error Boundary](https://ru.reactjs.org/docs/error-boundaries.html#introducing-error-boundaries). Этот пакет предоставляет свою версию Error Boundary которая залогирует ошибку через общий логгер и отобразит заглушку для обернутого компонента если произошла ошибка.
86
+ To handle errors during rendering, React uses [Error Boundary](https://ru.reactjs.org/docs/error-boundaries.html#introducing-error-boundaries). This package provides its own version of Error Boundary which will log an error through a generic logger and display a stub for the wrapped component if an error occurs.
82
87
 
83
88
  ### ErrorBoundary
84
89
 
85
- Error Boundary компонент, который следит за ошибками ниже по дереву и в случае возникшей ошибки рендера залогирует ошибку и отобразит компонент `fallbackComponent` (передается как пропс, по дефолту это FallbackError из этого пакета) вместо упавшего поддерева рендера.
90
+ Error Boundary component that monitors errors down the tree and, in case of a render error, will log an error and display the `fallbackComponent` component (passed as a props, by default it is a FallbackError from this package) instead of the fallen render subtree.
86
91
 
87
- Можно переопределить `fallbackComponent` через провайдер `ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN`.
92
+ You can override the `fallbackComponent` through the `ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN` provider.
88
93
 
89
94
  ### FallbackError
90
95
 
91
- Компонент используемый по умолчанию как заглушка для поддерева в котором призошла ошибка рендера
96
+ Component used by default as a stub for a subtree in which a render error occurred
92
97
 
93
98
  ### withError
94
99
 
95
- Хок оборачивающий компонент в ErrorBoundary.
100
+ Hook wrapping component in ErrorBoundary.
96
101
 
97
102
  ## lazy
98
103
 
99
- Для динамического импорта компонентов с поддержкой SSR, существует high order компонент `lazy`:
104
+ To dynamically import components with SSR support, there is a high order `lazy` component:
100
105
 
101
106
  ```tsx
102
107
  import { lazy } from '@tramvai/react';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/react",
3
- "version": "1.60.1",
3
+ "version": "1.62.1",
4
4
  "description": "",
5
5
  "main": "lib/react.js",
6
6
  "typings": "lib/react.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@tinkoff/dippy": "0.7.38",
27
27
  "@tinkoff/utils": "^2.1.2",
28
28
  "@tinkoff/url": "0.7.37",
29
- "@tramvai/core": "1.60.1",
29
+ "@tramvai/core": "1.62.1",
30
30
  "react": ">=16.8.0",
31
31
  "react-dom": ">=16.8.0",
32
32
  "tslib": "^2.0.3"
package/README.en.md DELETED
@@ -1,109 +0,0 @@
1
- # React
2
-
3
- `@tramvai/react` - library for integrating tramvai features with `React` components
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm i --save @tramvai/react
9
- ```
10
-
11
- ## DI
12
-
13
- When creating components, you may need to get data from di, for this there is a hook `useDi` and HoC `withDi`
14
-
15
- ### useDi
16
-
17
- ```tsx
18
- type useDi = (deps: Record<string, string | Token>) => Record<string, any>;
19
- ```
20
-
21
- ```tsx
22
- type useDi = (dep: string | Token) => any;
23
- ```
24
-
25
- A hook into which we can pass both an object with the required dependencies and an object with data will be returned to us, as well as a single token, where the result will be returned to us. When we call `useDi`, we get data from di and if we don't find data in di, an error will occur.
26
-
27
- ```javascript
28
- import React from 'react';
29
- import { useDi } from '@tramvai/react';
30
-
31
- const MyComponent = () => {
32
- const { logger } = useDi({ logger: 'logger' }); // pass the object
33
- const Region = useDi(regionToken); // pass a single token
34
-
35
- logger.info('text');
36
-
37
- return (
38
- <div>
39
- Component
40
- <Region />
41
- </div>
42
- );
43
- };
44
- ```
45
-
46
- ### withDi
47
-
48
- ```tsx
49
- type withDi = (
50
- deps: Record<string, string | Token>
51
- ) => (wrapper: React.ReactElement<any>) => React.ReactElement<any>;
52
- ```
53
-
54
- A HoC that allows you to wrap any components, get data from `DI` and pass the result with dependencies to the props of the component
55
-
56
- ```javascript
57
- import React from 'react';
58
- import { withDi } from '@tramvai/react';
59
-
60
- @withDi({ logger: LOGGER_TOKEN })
61
- class BoxyPage extends Component {
62
- render() {
63
- this.props.logger.info('text');
64
- return <div>Component</div>;
65
- }
66
- }
67
- ```
68
-
69
- ### useDiContainer
70
-
71
- ```tsx
72
- type useDiContainer = () => DI.Container;
73
- ```
74
-
75
- Getting an instance of a DI container that has been added to the application context.
76
-
77
- It is better not to use this hook, as it is very low-level and is intended for developing new hooks
78
-
79
- ## Error
80
-
81
- To handle errors during rendering, React uses [Error Boundary](https://ru.reactjs.org/docs/error-boundaries.html#introducing-error-boundaries). This package provides its own version of Error Boundary which will log an error through a generic logger and display a stub for the wrapped component if an error occurs.
82
-
83
- ### ErrorBoundary
84
-
85
- Error Boundary component that monitors errors down the tree and, in case of a render error, will log an error and display the `fallbackComponent` component (passed as a props, by default it is a FallbackError from this package) instead of the fallen render subtree.
86
-
87
- You can override the `fallbackComponent` through the `ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN` provider.
88
-
89
- ### FallbackError
90
-
91
- Component used by default as a stub for a subtree in which a render error occurred
92
-
93
- ### withError
94
-
95
- Hook wrapping component in ErrorBoundary.
96
-
97
- ## lazy
98
-
99
- To dynamically import components with SSR support, there is a high order `lazy` component:
100
-
101
- ```tsx
102
- import { lazy } from '@tramvai/react';
103
-
104
- const LazyComponent = lazy(() => import('./components/foo'), {
105
- loading: <div>Загрузка...</div>,
106
- });
107
-
108
- <LazyComponent />;
109
- ```