Skip to content

Commit c987634

Browse files
committed
fix: emit current property value immediately in listener effect
Legacy addListener does NOT emit on subscribe — only on changes. Without this, hooks stayed undefined forever if the value never changed. Now the effect reads property.value synchronously when subscribing, then the listener handles subsequent updates.
1 parent fd3c324 commit c987634

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/hooks/useRiveProperty.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
6666
useEffect(() => {
6767
if (!property) return;
6868

69-
// If an override callback is provided, use it.
70-
// Otherwise, use the default callback.
69+
// Deliver the current value immediately so the hook transitions from
70+
// undefined → value without waiting for a property change.
71+
// (Legacy addListener does NOT emit on subscribe — only on changes.
72+
// Experimental valueStream emits the current value as its first element.)
73+
if (!options.onPropertyEventOverride) {
74+
setValue(property.value);
75+
}
76+
7177
const removeListener = options.onPropertyEventOverride
7278
? property.addListener(options.onPropertyEventOverride)
7379
: property.addListener((newValue) => {

0 commit comments

Comments
 (0)