Skip to content

fix: useRive* hooks start undefined, value delivered via listener#184

Draft
mfazekas wants to merge 4 commits intomainfrom
feat/hooks-undefined-initial-value
Draft

fix: useRive* hooks start undefined, value delivered via listener#184
mfazekas wants to merge 4 commits intomainfrom
feat/hooks-undefined-initial-value

Conversation

@mfazekas
Copy link
Collaborator

@mfazekas mfazekas commented Mar 19, 2026

Stacked on #183. diff

useRiveNumber/String/Boolean/Color/Enum hooks now always start as undefined and receive the current value through the listener's first emission, instead of reading property.value synchronously on mount. This unifies startup behavior across legacy and experimental backends.

Consumers should guard renders: value !== undefined ? value.toFixed(2) : '…'

…patibility

Add async equivalents for all sync ViewModel/RiveFile methods (createInstanceByNameAsync,
getValueAsync, viewModelByNameAsync, etc.) and mark legacy sync methods as @deprecated.
Native implementations wrap sync calls in Promise.async on both iOS and Android.
Initial value is no longer read synchronously from property.value.
Instead the hook always starts as undefined and receives the current
value through the listener's first emission. This unifies the startup
shape across legacy (sync emit) and experimental (async valueStream)
backends, so consumers always handle the loading state.

The setter callback now uses React state for updater functions instead
of reading property.value synchronously.
@mfazekas mfazekas changed the base branch from feat/async-api-compat to main March 19, 2026 12:51
@mfazekas mfazekas force-pushed the feat/hooks-undefined-initial-value branch from 4d3d3a6 to 54c186e Compare March 19, 2026 13:20
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant