Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions runtimes/data-binding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ To begin, we need to get a reference to a particular view model. This can be don
const { riveFile } = useRiveFile(require('./my_file.riv'));

// Get reference by name
const namedVM = riveFile?.viewModelByName('My View Model');
const namedVM = await riveFile?.viewModelByNameAsync('My View Model');

// Get reference by index
const indexVM = riveFile?.viewModelByIndex(0);
// Get all view model names
const vmNames = await riveFile?.getViewModelNamesAsync(); // ['My View Model', ...]

// Get reference to the default artboard view model
const defaultVM = riveFile?.defaultArtboardViewModel();
const defaultVM = await riveFile?.defaultArtboardViewModelAsync();
```
</Tab>
<Tab title="Legacy Runtime">
Expand Down Expand Up @@ -610,17 +610,17 @@ Once we have a reference to a view model, it can be used to create an instance.
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings', instanceName: 'UserSettings' });

// From a ViewModel object
const viewModel = riveFile?.viewModelByName('My View Model');
const viewModel = await riveFile?.viewModelByNameAsync('My View Model');
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
const newInstance = useViewModelInstance(viewModel, { useNew: true });

// With required: true (throws if null, use with Error Boundary)
const instance = useViewModelInstance(riveFile, { required: true });

// With onInit to set initial values synchronously
// With onInit to set initial values
const instance = useViewModelInstance(riveFile, {
onInit: (vmi) => {
vmi.numberProperty('health')!.value = 100;
vmi.numberProperty('health')?.set(100);
},
});

Expand Down Expand Up @@ -3267,10 +3267,10 @@ For more information on list properties, see the [Data Binding List Property](/e
} = useRiveList('todos', instance);

// Add a new todo item
const handleAddItem = () => {
const todoItemViewModel = riveFile?.viewModelByName('TodoItem');
const handleAddItem = async () => {
const todoItemViewModel = await riveFile?.viewModelByNameAsync('TodoItem');
if (todoItemViewModel) {
const newTodoItem = todoItemViewModel.createInstance();
const newTodoItem = await todoItemViewModel.createBlankInstanceAsync();
if (newTodoItem) {
// Set some initial values
newTodoItem.stringProperty('description')?.set('Buy groceries');
Expand All @@ -3280,10 +3280,10 @@ For more information on list properties, see the [Data Binding List Property](/e
};

// Insert item at specific index
const handleInsertItem = () => {
const todoItemViewModel = riveFile?.viewModelByName('TodoItem');
const handleInsertItem = async () => {
const todoItemViewModel = await riveFile?.viewModelByNameAsync('TodoItem');
if (todoItemViewModel) {
const newTodoItem = todoItemViewModel.createInstance();
const newTodoItem = await todoItemViewModel.createBlankInstanceAsync();
if (newTodoItem) {
addInstanceAt(newTodoItem, 0); // Insert at beginning
}
Expand Down