Skip to content

Commit

Permalink
fix: avoid startTransition in React Native (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Oct 31, 2024
1 parent 65e3f59 commit 1d1d3aa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/FlagProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IFlagProvider {
unleashClient?: UnleashClient;
startClient?: boolean;
stopClient?: boolean;
startTransition?: (fn: () => void) => void;
}

const offlineConfig: IConfig = {
Expand All @@ -23,14 +24,16 @@ const offlineConfig: IConfig = {
// save startTransition as var to avoid webpack analysis (https://github.com/webpack/webpack/issues/14814)
const _startTransition = 'startTransition';
// fallback for React <18 which doesn't support startTransition
const startTransition = React[_startTransition] || (fn => fn());
// Fallback for React <18 and exclude startTransition if in React Native
const defaultStartTransition = React[_startTransition] || (fn => fn());

const FlagProvider: FC<PropsWithChildren<IFlagProvider>> = ({
config: customConfig,
children,
unleashClient,
startClient = true,
stopClient = true,
startTransition = defaultStartTransition
}) => {
const config = customConfig || offlineConfig;
const client = React.useRef<UnleashClient>(
Expand Down

0 comments on commit 1d1d3aa

Please sign in to comment.