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
In this solution it is not possible to use any Ant's settings from React Context, because it does not have access to the React at all. It means that notifications will not be styled properly and could look different from the rest of the application.
85
-
86
-
So, this is not a solution.
87
-
88
-
### 🔴 Just `.watch` an [_Event_](https://effector.dev/en/api/effector/event/) in a component
89
-
90
-
It is possible to call `.watch`-method of an [_Event_](https://effector.dev/en/api/effector/event/) in a component.
In this solution we do not respect [Fork API rules](/magazine/fork_api_rules), it means that we could have memory leaks, problems with test environments and Storybook-like tools.
121
-
122
-
So, this is not a solution.
58
+
Let us take a look on a ideal solution and a couple of not-so-good solutions.
123
59
124
60
### 🟢 Save `notification` instance to a [_Store_](https://effector.dev/docs/api/effector/store)
125
61
126
-
We can combine the previous two solutions and save `notification` API-instance to a [_Store_](https://effector.dev/docs/api/effector/store). Let us create a couple new units to do it.
62
+
The best way is saving `notification` API-instance to a [_Store_](https://effector.dev/docs/api/effector/store) and using it thru [_Effect_](https://effector.dev/docs/api/effector/effect). Let us create a couple new units to do it.
127
63
128
64
```ts
129
65
// notifications.ts
@@ -210,6 +146,78 @@ sample({
210
146
});
211
147
```
212
148
149
+
Now we have a valid solution to handle [_Events_](https://effector.dev/en/api/effector/event/) on UI-layer without exposing the whole data-flow.
150
+
151
+
However, if you want to know why other (maybe more obvious) solutions are not so good, you can read about them below 👇
152
+
153
+
::: details Not-so-good solutions
154
+
155
+
### 🔴 Global `notification` service
156
+
157
+
Ant Design allows using global notification instance.
158
+
159
+
```ts{7-17}
160
+
// model.ts
161
+
import { createEvent, createEffect, sample } from 'effector';
In this solution it is not possible to use any Ant's settings from React Context, because it does not have access to the React at all. It means that notifications will not be styled properly and could look different from the rest of the application.
180
+
181
+
So, this is not a solution.
182
+
183
+
### 🔴 Just `.watch` an [_Event_](https://effector.dev/en/api/effector/event/) in a component
184
+
185
+
It is possible to call `.watch`-method of an [_Event_](https://effector.dev/en/api/effector/event/) in a component.
In this solution we do not respect [Fork API rules](/magazine/fork_api_rules), it means that we could have memory leaks, problems with test environments and Storybook-like tools.
216
+
217
+
So, this is not a solution.
218
+
219
+
:::
220
+
213
221
## Summary
214
222
215
223
To bind some UI-framework specific API to Effector's data-flow we need to follow these steps:
0 commit comments