Skip to content

Commit 61c5558

Browse files
committed
fix: allow useRiveFile to work with undefined input
1 parent 24ce242 commit 61c5558

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/hooks/useRiveFile.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ function transformFilesHandledMapping(
7070
type RiveFileHookResult =
7171
| { riveFile: RiveFile; isLoading: false; error: null }
7272
| { riveFile: null; isLoading: true; error: null }
73-
| { riveFile: null; isLoading: false; error: string };
73+
| { riveFile: null; isLoading: false; error: string }
74+
| { riveFile: null; isLoading: false; error: null };
7475

7576
export function useRiveFile(
76-
input: RiveFileInput,
77+
input: RiveFileInput | undefined,
7778
options: UseRiveFileOptions = {}
7879
): RiveFileHookResult {
7980
const [result, setResult] = useState<RiveFileHookResult>({
@@ -122,7 +123,15 @@ export function useRiveFile(
122123
);
123124
}
124125

125-
setResult({ riveFile: currentFile!, isLoading: false, error: null });
126+
if (currentFile == null) {
127+
setResult({
128+
riveFile: null,
129+
isLoading: false,
130+
error: 'Failed to load Rive file: Input not provided.',
131+
});
132+
} else {
133+
setResult({ riveFile: currentFile!, isLoading: false, error: null });
134+
}
126135
} catch (err) {
127136
console.error(err);
128137
setResult({

0 commit comments

Comments
 (0)