Preview: packages are not published yet.
Learn · board 4
A call in each direction
React can call the native app and the native app can call React, with types on both ends. Pick a direction and follow one call down through the layers and its result back up.
Preview. This board shows an API that is not released yet. It ships after the base library, and its names may change.
A React screen asks the app to open its native checkout and waits for the result.
Your React screenyou write it
const shop = useContract(Shop) const outcome = await shop.openCheckout(order)outcome
Library, JS sidegenerated
shop.openCheckout(order) // a direct call: no envelope, no JSON
Nitrothe bridge
JS object -> struct Order( id: String, total: Double, items: [String])
Library, native sidegenerated
// HybridShop: what JavaScript reaches let result = try await consumer .openCheckout(order: order) // goes to whoever provides Shop now
Your native appyou write it
@MainActor final class ShopHost: ShopProvider {
func openCheckout(order: Order)
async throws -> Outcome { ... }
// ...the other members of ShopProvider
}
try Contracts.provide(Shop.self, ShopHost())- 1A screen asks for the Shop contract and awaits a call.
- 2The order goes down as a JavaScript object. It is never turned into text.
- 3Nitro converts it into a Swift struct.
- 4The library hands it to whatever the app provided for Shop.
- 5Your class opens the native checkout and waits for the person.
- 6The Outcome comes back up, perhaps minutes later.
- 7Nitro converts it into a JavaScript object.
- 8The Promise resolves.
- 9The await continues. The late result is the result of the call itself: there is no event to subscribe to.
- Previous board: from a React project to one native dependency
- Read: contracts, provide and consume