-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuseRiveString.ts
More file actions
28 lines (26 loc) · 971 Bytes
/
useRiveString.ts
File metadata and controls
28 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {
type ViewModelInstance,
type ViewModelStringProperty,
} from '../specs/ViewModel.nitro';
import type { UseRivePropertyResult } from '../types';
import { useRiveProperty } from './useRiveProperty';
const STRING_PROPERTY_OPTIONS = {
getProperty: (vmi: ViewModelInstance, p: string) => vmi.stringProperty(p),
};
/**
* Hook for interacting with string ViewModel instance properties.
*
* @param path - The path to the string property
* @param viewModelInstance - The ViewModelInstance containing the string property to operate on
* @returns An object with the number value, a setter function, and an error if the property is not found
*/
export function useRiveString(
path: string,
viewModelInstance?: ViewModelInstance | null
): UseRivePropertyResult<string> {
const [value, setValue, error] = useRiveProperty<
ViewModelStringProperty,
string
>(viewModelInstance, path, STRING_PROPERTY_OPTIONS);
return { value, setValue, error };
}