Repository navigation
Add useCodePush() - #111
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the new hook and shared update-state integration.
No open issues 🎉
What changed in this PR
Adds useCodePush() so components inside CodePushProvider can display update-check state and trigger update actions. It builds on the Provider introduced in #107 while also reflecting checks made through legacy APIs.
Changes:
- Adds a Provider-backed hook exposing check state, incompatible releases, errors, and update actions.
- Reports checks from
CodePush.jsto a shared, React-independent store. - Adds public types, usage documentation, and unit tests for state transitions and subscriptions.
| File | Description |
|---|---|
typings/react-native-code-push.d.ts |
Declares the hook, state, and action types. |
src/update-state/update-store.ts |
Adds the observable update-state store. |
src/update-state/update-state.ts |
Handles check results, failures, and overlapping checks. |
src/update-state/__tests__/update-store.test.ts |
Tests subscriptions, snapshot identity, and store isolation. |
src/update-state/__tests__/update-state.test.ts |
Tests state transitions and overlapping checks. |
src/react/use-code-push.ts |
Adds the hook with store subscriptions and a Provider guard. |
src/react/store-context.ts |
Defines context for the store and update actions. |
src/react/code-push-provider.tsx |
Supplies store context to child components. |
docs/api-js.md |
Documents hook behavior and usage. |
CodePush.js |
Reports checks to the store and exports the wired hook. |
Review effort: Balanced
ofalvai
force-pushed
the
add-use-code-push
branch
from
November 10, 2026 08:44
deed861 to
3bc0c58
Compare
sajtizsolt
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
#107 added
<CodePushProvider>, which runs the update checks for the app. Components still can't show what CodePush is doing: whether a check is running, whether an update is waiting, or why the last check failed. Today an app has to pass callbacks tosync()and keep that state itself.Change
Adds a new React hook,
useCodePush(). It returns the update state and the functions that change it, and re-renders the component when the state changes. It works inside<CodePushProvider>(and throws outside it, because without the Provider nothing callsnotifyAppReady()and every update rolls back).The state has
isChecking,isUpdateAvailable,availableUpdate,incompatibleUpdateandcheckError.incompatibleUpdateis set when the server has a release that this binary can't install because of the update's target version constraint. Until now only a callback reported this.checkForUpdate()inCodePush.jsreports each check to a small store.sync()and thecodePush()HOC check throughcheckForUpdate(), so every check shows in the state: the Provider's, the hook's, and direct calls to the old functions. The hook reads the store with useSyncExternalStore.Decisions
CodePush.jsalone and implemented everything in/src(wrappedsync()in the hook, guessing the check's progress from status callbacks). It came out more than twice as large, missed direct calls and the HOC, never knew which updatesync()found, and needed a "this call doesn't update the hook's state" warning all over the docs. In this version, the store lives at module level, outside React, because the old functions must keep updating it.sync(options)andcheckForUpdate({ deploymentKey })take no callbacks, unlike the existingcodePush.sync()andcodePush.checkForUpdate()methods: This is a new public API, so it is the time to define a modern and intuitive API. Sync status and download progress should become state instead (next PR).isUpdateAvailableis false for an update that failed to install before, becausesync()skips those by default (existing behavior). It isn't exact whenrollbackRetryOptionsallows a retry, but close enough.incompatibleUpdate.targetBinaryVersionis an optional field: We plan an automatic compatibility check (like Expo's fingerprints), which won't require setting a "target" binary version at all.Out of scope
🤖 Generated with Claude Code