Skip to content

Commit

Permalink
fix: fixed useIsCloudAvailable hook reporting wrong initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
mfkrause committed May 26, 2024
1 parent 3760f6b commit 394af25
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useIsCloudAvailable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { NativeEventEmitter, NativeModules, Platform, DeviceEventEmitter } from 'react-native';
import RNCloudStorage from '../RNCloudStorage';

/**
* A hook that tests whether or not the cloud storage is available.
Expand All @@ -10,6 +11,9 @@ export const useIsCloudAvailable = (_iCloudTimeout?: number) => {
const [isAvailable, setIsAvailable] = useState(false);

useEffect(() => {
// Set the initial availability state
RNCloudStorage.isCloudAvailable().then(setIsAvailable);

// Listen for changes to the cloud availability using the native event emitter
let eventEmitter: NativeEventEmitter | typeof DeviceEventEmitter;
if (Platform.OS === 'ios') {
Expand Down

0 comments on commit 394af25

Please sign in to comment.