{"_id":"@affordant/react","_rev":"2-8d7f064689b79e392891013f0f4f5f4e","name":"@affordant/react","dist-tags":{"latest":"0.3.0"},"versions":{"0.2.0":{"name":"@affordant/react","version":"0.2.0","keywords":["hateoas","hypermedia","affordance","react","hooks"],"author":{"name":"Florian Leroy"},"license":"MIT","_id":"@affordant/react@0.2.0","maintainers":[{"name":"hijoxx","email":"floroy32@gmail.com"}],"homepage":"https://leroy-florian.github.io/Affordant/","bugs":{"url":"https://github.com/Leroy-Florian/Affordant/issues"},"dist":{"shasum":"92624af9c5f90da7c17192521d3e6586ad0f10ad","tarball":"https://registry.npmjs.org/@affordant/react/-/react-0.2.0.tgz","fileCount":10,"integrity":"sha512-cDN6pTZ8hfG7uh+AyavolK/rU2JCNdByZdg1eXemF5foUr4MVIEXTvd48hG2hUVcO+KNntM/mYqYniMyjQz4AA==","signatures":[{"sig":"MEYCIQDw+OPxcvgbreO7/lOuOT+c7sizaFXrOQ+o3dewPMKU7AIhAPXNzCgEmm/x6YXAa38NHee4OCxatFj3JVxIV5KNsGm0","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@affordant%2freact@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":11268},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./effect":{"types":"./dist/effect.d.ts","import":"./dist/effect.js"}},"gitHead":"f6e1abef80c7cbbf221fc6781d60c66a683cc7a9","scripts":{"test":"vitest run","build":"node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json","typecheck":"tsc -p tsconfig.json"},"_npmUser":{"name":"hijoxx","email":"floroy32@gmail.com"},"repository":{"url":"git+https://github.com/Leroy-Florian/Affordant.git","type":"git","directory":"packages/react"},"_npmVersion":"10.8.2","description":"React adapter for Affordant: gate UI on the server's affordances and invoke them with either invoker — the vanilla Promise one or the Effect one.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"affordant":"^0.2.0","@affordant/contract":"^0.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@affordant/effect":"*","effect-react-bridge":"*"},"peerDependencies":{"react":">=18","effect":"^3.21.0","@affordant/effect":">=0.1.0","effect-react-bridge":">=0.1.0"},"peerDependenciesMeta":{"effect":{"optional":true},"@affordant/effect":{"optional":true},"effect-react-bridge":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/react_0.2.0_1780691935761_0.20227644127451305","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@affordant/react","version":"0.3.0","description":"React adapter for Affordant: gate UI on the server's affordances and follow them with hooks. Zero runtime dependencies beyond React.","license":"MIT","author":{"name":"Florian Leroy"},"repository":{"type":"git","url":"git+https://github.com/Leroy-Florian/Affordant.git","directory":"packages/react"},"homepage":"https://leroy-florian.github.io/Affordant/","bugs":{"url":"https://github.com/Leroy-Florian/Affordant/issues"},"keywords":["hateoas","hypermedia","affordance","react","hooks"],"type":"module","sideEffects":false,"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"publishConfig":{"access":"public"},"dependencies":{"affordant":"^0.2.0","@affordant/contract":"^0.2.0"},"peerDependencies":{"react":">=18"},"scripts":{"build":"node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json","typecheck":"tsc -p tsconfig.json","test":"vitest run"},"_id":"@affordant/react@0.3.0","gitHead":"907560699b3aa6258c60ce7750044c52e14eeb41","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-FCSicCuqvip+BnFSrq+uknwgZkKOWdgfdUwv3l/iSb08RMi7HbvFtL+uepGyWemRf+UzTwtc4STuUIP6Z/DY6g==","shasum":"c90b0e530d58d6ec1a373193be3399ec949d89c2","tarball":"https://registry.npmjs.org/@affordant/react/-/react-0.3.0.tgz","fileCount":6,"unpackedSize":7536,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@affordant%2freact@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICuFc6jV/1UrdxJWQxSg4aeLbWiHXStU/HLIGDWdA9BgAiBLHDeWmp65NBKioOSTXZ54z0GXHN2XZ+JnpXrz4RjyFQ=="}]},"_npmUser":{"name":"hijoxx","email":"floroy32@gmail.com"},"directories":{},"maintainers":[{"name":"hijoxx","email":"floroy32@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react_0.3.0_1780728799973_0.13173442438140048"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-05T20:38:55.603Z","modified":"2026-06-06T06:53:20.349Z","0.2.0":"2026-06-05T20:38:55.893Z","0.3.0":"2026-06-06T06:53:20.110Z"},"bugs":{"url":"https://github.com/Leroy-Florian/Affordant/issues"},"author":{"name":"Florian Leroy"},"license":"MIT","homepage":"https://leroy-florian.github.io/Affordant/","keywords":["hateoas","hypermedia","affordance","react","hooks"],"repository":{"type":"git","url":"git+https://github.com/Leroy-Florian/Affordant.git","directory":"packages/react"},"description":"React adapter for Affordant: gate UI on the server's affordances and follow them with hooks. Zero runtime dependencies beyond React.","maintainers":[{"name":"hijoxx","email":"floroy32@gmail.com"}],"readme":"# @affordant/react\n\nReact adapter for [Affordant](https://leroy-florian.github.io/Affordant/). Gate your UI on what the server offers, and follow affordances with hooks. No runtime dependency beyond React.\n\n## Install\n\n```sh\nnpm install @affordant/react react\n```\n\n## Gating\n\n```tsx\nimport { useAffordance } from '@affordant/react'\n\nfunction CancelButton({ order }) {\n  const cancel = useAffordance(order, 'cancel')\n  if (!cancel.can) return null\n  return <button onClick={...}>Cancel</button>\n}\n```\n\n## Following\n\n```tsx\nimport { useAffordance, useFollow } from '@affordant/react'\n\nconst cancel = useAffordance(order, 'cancel')\nconst { run, running } = useFollow()\n\n<button disabled={!cancel.can || running} onClick={() => run(cancel.action!, { token })}>\n  Cancel\n</button>\n```\n\n`run` resolves with the raw `Response` and re-throws on failure, with `error` set.\n\n## Using Effect\n\nThere is no Effect entry point, and none is needed: `run` (and the underlying `follow`) return a `Promise<Response>`, which drops into Effect with a one-line wrap — `Effect.tryPromise(() => follow(action, init))`. Affordant stays Effect-compatible without shipping an Effect dependency.\n\n## API\n\n| Export | Description |\n|---|---|\n| `useAffordance(resource, rel)` | `{ can, action }` — memoised, null-safe gating over `can` / `actionFor`. |\n| `useFollow()` | `{ running, error, run }` — follow an action, tracking request state. |\n\n`react` is a peer dependency.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}