Skip to content

Commit c8a3fd3

Browse files
Pawan KumarPawan Kumar
Pawan Kumar
authored and
Pawan Kumar
committed
add global toast type
1 parent 8b52db6 commit c8a3fd3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

example/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type Toast = React.RefObject<
2+
import('react-native-magnus').SnackbarRef
3+
>['current'];
4+
5+
declare global {
6+
const toast: Toast;
7+
}
8+
9+
declare var toast: Toast;

example/src/components/Snackbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const SnackbarComponent: React.FC = () => {
1717
block
1818
p="lg"
1919
onPress={() => {
20-
(global as any).toast.show('Hello World', {
20+
toast?.show('Hello World', {
2121
duration: 5000,
2222
suffix: (
2323
<Button bg="green500" fontSize="sm" p="sm" px="md">

example/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { createStackNavigator } from '@react-navigation/stack';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { Snackbar, SnackbarRef, ThemeProvider } from 'react-native-magnus';
4+
import { Snackbar, ThemeProvider } from 'react-native-magnus';
55
import AppLoading from 'expo-app-loading';
66
import { useFonts } from 'expo-font';
77

@@ -60,7 +60,7 @@ const App = () => {
6060
<Snackbar
6161
px="xl"
6262
py="lg"
63-
ref={(ref) => ((global as any).toast = ref)}
63+
ref={(ref) => (global.toast = ref)}
6464
color="white"
6565
fontSize="lg"
6666
duration={2000}

0 commit comments

Comments
 (0)