Skip to content

Commit 1d30892

Browse files
committed
fix(toast): cycle issues
1 parent 7ea0222 commit 1d30892

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/components/toast/toast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { ViewRef } from '../../helpers/types';
99
import { createContext } from '../../helpers/utils';
1010
import * as ToastPrimitive from '../../primitives/toast';
1111
import type { ToastComponentProps } from '../../providers/toast';
12-
import { useToastConfig } from '../../providers/toast';
12+
import { useToastConfig } from '../../providers/toast/toast-config.context';
1313
import { Button } from '../button';
1414
import type { PressableFeedbackHighlightRootAnimation } from '../pressable-feedback';
1515
import { useToastRootAnimation } from './toast.animation';

src/providers/toast/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export { ToastProvider, useToast, useToastConfig } from './provider';
1+
export { ToastProvider, useToast } from './provider';
2+
export { useToastConfig } from './toast-config.context';
23
export type * from './types';

src/providers/toast/provider.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useSharedValue } from 'react-native-reanimated';
1111
import { DefaultToast } from '../../components/toast/toast';
1212
import { InsetsContainer } from './insets-container';
1313
import { toastReducer } from './reducer';
14+
import { ToastConfigContext } from './toast-config.context';
1415
import { ToastItemRenderer } from './toast-item-renderer';
1516
import type {
1617
ToastComponentProps,
@@ -29,13 +30,6 @@ const DEFAULT_DURATION = 4000;
2930
*/
3031
const ToasterContext = createContext<ToasterContextValue | null>(null);
3132

32-
/**
33-
* Context for global toast configuration
34-
*/
35-
const ToastConfigContext = createContext<ToastGlobalConfig | undefined>(
36-
undefined
37-
);
38-
3933
/**
4034
* Merges global config with local config, ensuring local config takes precedence
4135
* Only includes defined values from localConfig to avoid overriding global config with undefined
@@ -428,18 +422,3 @@ export function useToast() {
428422
isToastVisible: context.isToastVisible,
429423
};
430424
}
431-
432-
/**
433-
* Hook to access global toast configuration
434-
*
435-
* @returns Global toast configuration or undefined if not set
436-
*
437-
* @example
438-
* ```tsx
439-
* const globalConfig = useToastConfig();
440-
* // Use globalConfig.variant, globalConfig.placement, etc.
441-
* ```
442-
*/
443-
export function useToastConfig(): ToastGlobalConfig | undefined {
444-
return useContext(ToastConfigContext);
445-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { createContext, useContext } from 'react';
2+
import type { ToastGlobalConfig } from './types';
3+
4+
/**
5+
* Context for global toast configuration
6+
* Extracted to separate file to avoid circular dependencies with toast component
7+
*/
8+
const ToastConfigContext = createContext<ToastGlobalConfig | undefined>(
9+
undefined
10+
);
11+
12+
/**
13+
* Hook to access global toast configuration
14+
*
15+
* @returns Global toast configuration or undefined if not set
16+
*
17+
* @example
18+
* ```tsx
19+
* const globalConfig = useToastConfig();
20+
* // Use globalConfig.variant, globalConfig.placement, etc.
21+
* ```
22+
*/
23+
export function useToastConfig(): ToastGlobalConfig | undefined {
24+
return useContext(ToastConfigContext);
25+
}
26+
27+
export { ToastConfigContext };

0 commit comments

Comments
 (0)