Commit 8681b0d
authored
feat: added modal.onMounted handler (#1082)
- Added `modal.onMounted` handler to global eventHandlers.
This event handler is triggered within the `useEffect` of the Modal
component at mounting time.
---
Example usage
```tsx
const App = () => {
return (
<SendbirdProvider
eventHandlers={{
modal: {
onMounted({ id, close }) {
// Push the state to prevent the browser's back button press
window.history.pushState({ id }, '');
// Close the modal if the back button is pressed
const onPopState = (e: PopStateEvent) => {
e.preventDefault(); // Prevents the default back action
close(); // Closes the modal
};
window.addEventListener('popstate', onPopState);
// Cleanup function
return () => {
// Clear the current state when the modal is closed without using the back button
if (window.history.state?.id === id) window.history.back();
window.removeEventListener('popstate', onPopState);
};
}
}
}}
/>
);
};
```
ticket: [CLNP-3057]
[CLNP-3057]:
https://sendbird.atlassian.net/browse/CLNP-3057?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ1 parent 69a2cbd commit 8681b0d
3 files changed
+45
-62
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 28 | + | |
| 29 | + | |
37 | 30 | | |
38 | 31 | | |
39 | 32 | | |
| |||
44 | 37 | | |
45 | 38 | | |
46 | 39 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 40 | + | |
51 | 41 | | |
52 | 42 | | |
53 | 43 | | |
| |||
97 | 87 | | |
98 | 88 | | |
99 | 89 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | 90 | | |
105 | 91 | | |
106 | 92 | | |
107 | 93 | | |
| 94 | + | |
| 95 | + | |
108 | 96 | | |
109 | 97 | | |
110 | 98 | | |
| |||
118 | 106 | | |
119 | 107 | | |
120 | 108 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
128 | 113 | | |
129 | 114 | | |
130 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
131 | 123 | | |
132 | 124 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
147 | 129 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
159 | 134 | | |
160 | 135 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 136 | + | |
165 | 137 | | |
166 | 138 | | |
167 | 139 | | |
168 | 140 | | |
169 | 141 | | |
170 | 142 | | |
171 | 143 | | |
172 | | - | |
173 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
174 | 147 | | |
175 | 148 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
| |||
0 commit comments