{"id":13450637,"url":"https://github.com/tylervipond/use-as-bind","last_synced_at":"2025-03-23T16:31:50.281Z","repository":{"id":57387861,"uuid":"267979086","full_name":"tylervipond/use-as-bind","owner":"tylervipond","description":"React Hook for using as-bind with a WASM source","archived":false,"fork":false,"pushed_at":"2024-04-23T01:56:05.000Z","size":1258,"stargazers_count":65,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T11:07:23.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tylervipond.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-30T00:09:56.000Z","updated_at":"2024-06-14T04:43:24.000Z","dependencies_parsed_at":"2024-07-31T07:12:30.472Z","dependency_job_id":"cfad56aa-a361-4653-a0c0-c7a84879449d","html_url":"https://github.com/tylervipond/use-as-bind","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.23076923076923073","last_synced_commit":"136dd6bd8e724fe639cea12b0c0b1cb8dcfa28e4"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylervipond%2Fuse-as-bind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylervipond%2Fuse-as-bind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylervipond%2Fuse-as-bind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylervipond%2Fuse-as-bind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tylervipond","download_url":"https://codeload.github.com/tylervipond/use-as-bind/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245130864,"owners_count":20565734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:00:36.880Z","updated_at":"2025-03-23T16:31:49.961Z","avatar_url":"https://github.com/tylervipond.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# use-as-bind\n\n\u003e React Hook for using [as-bind](https://github.com/torch2424/as-bind) with a WASM source\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![NPM](https://img.shields.io/npm/v/use-as-bind.svg)](https://www.npmjs.com/package/use-as-bind)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n![CI](https://github.com/tylervipond/use-as-bind/workflows/CI/badge.svg)\n\n## Install\n\n```bash\nnpm install react as-bind use-as-bind\n```\n\n## Basic Usage\n\n```tsx\nimport * as React from \"react\";\n\nimport { useAsBind } from \"use-as-bind\";\n\nconst Example = () =\u003e {\n  const { loaded, instance, error } = useAsBind(\"path/to/wasm.wasm\");\n  return (\n    \u003cdiv\u003e\n      {loaded \u0026\u0026 instance.exports.exampleFunction()}\n      {error \u0026\u0026 error.message}\n    \u003c/div\u003e\n  );\n};\n```\n\nFor convenience a hook creator is included:\n\n```tsx\nimport * as React from \"react\";\n\nimport { createAsBindHook } from \"use-as-bind\";\n\nconst useMyWasm = createAsBindHook(\"path/to/my-wasm.wasm\", {\n  imports: {\n    consoleLog: (message) =\u003e {\n      console.log(message);\n    },\n  },\n});\n\nconst Example = () =\u003e {\n  const { loaded, instance, error } = useMyWasm();\n  return (\n    \u003cdiv\u003e\n      {loaded \u0026\u0026 instance.exports.exampleFunction()}\n      {error \u0026\u0026 error.message}\n    \u003c/div\u003e\n  );\n};\n```\n\n## API\n\nuseAsBind takes two arguments:\n\n`useAsBind(source, options)`\n\n**_source_** - `string | WebAssembly.Module | BufferSource | Response | PromiseLike\u003cWebAssembly.Module\u003e` -\nThe source of the WebAssembly to be loaded. When a string is passed in it should be a url to a `.wasm` file which will be fetched and then instantiated. For non-string types check out the [as-bind docs for instantiate](https://github.com/torch2424/as-bind#instantiate)\n\n**_options_** - `Object` - An object that contains options to be used with as-bind and internally within the hook:\n\n- _imports_ - `Object` - An object of references to be made available to the loaded WASM file. For more information check out the [as-bind docs for importObject](https://github.com/torch2424/as-bind#importobject)\n\n## License\n\nMIT © [tylervipond](https://github.com/tylervipond)\n\n---\n\nThis hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylervipond%2Fuse-as-bind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylervipond%2Fuse-as-bind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylervipond%2Fuse-as-bind/lists"}