@rustra/react 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,5 +19,33 @@ function Item({ id }: { id: string }) {
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
The package provides `RustraProvider`, `useRustraEngine`, `useCommand`,
|
|
22
|
-
`useMutation`, and `
|
|
23
|
-
platform-specific Rustra engine before rendering the provider.
|
|
22
|
+
`useMutation`, `useEvent`, and `useSuspenseCommand`. React is a peer dependency;
|
|
23
|
+
configure the platform-specific Rustra engine before rendering the provider.
|
|
24
|
+
|
|
25
|
+
`useSuspenseCommand(commandFn, input?, options?)` is the Suspense-compatible read:
|
|
26
|
+
it suspends by throwing the in-flight promise until the command resolves, then
|
|
27
|
+
returns the value directly (a rejection is re-thrown to the nearest error
|
|
28
|
+
boundary). Results live in a module-level cache keyed by command name + serialized
|
|
29
|
+
input for the whole session — there is no eviction — so call
|
|
30
|
+
`invalidateCommands(commandName?)` to drop one command's entries (or, with no
|
|
31
|
+
argument, the whole cache) and make the next render re-invoke.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { Suspense } from 'react';
|
|
35
|
+
import { invalidateCommands, useSuspenseCommand } from '@rustra/react';
|
|
36
|
+
import { getItem, saveItem } from './generated/commands.js';
|
|
37
|
+
|
|
38
|
+
function Item({ id }: { id: string }) {
|
|
39
|
+
const item = useSuspenseCommand(getItem, { id }); // suspends until resolved
|
|
40
|
+
return <span>{item.name}</span>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function rename(id: string, name: string) {
|
|
44
|
+
await saveItem({ id, name });
|
|
45
|
+
invalidateCommands('getItem'); // next render of <Item> re-fetches
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
<Suspense fallback={<span>Loading...</span>}>
|
|
49
|
+
<Item id="item-1" />
|
|
50
|
+
</Suspense>;
|
|
51
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rustra/react",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "React and React Native bindings and hooks for rustra-bridge",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"react": ">=18.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@rustra/types": "^0.
|
|
33
|
+
"@rustra/types": "^0.9.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/react": "^19.0.0",
|