{"id":13532918,"url":"https://github.com/NelsonYong/solid-request","last_synced_at":"2025-04-01T21:31:25.129Z","repository":{"id":145028795,"uuid":"616380362","full_name":"NelsonYong/solid-request","owner":"NelsonYong","description":"solidjs  request","archived":false,"fork":false,"pushed_at":"2023-05-16T02:28:07.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T06:03:09.768Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/NelsonYong.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2023-03-20T09:24:24.000Z","updated_at":"2023-04-22T14:31:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"222d4180-a98d-4cdc-97ff-6e7f16535a5e","html_url":"https://github.com/NelsonYong/solid-request","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonYong%2Fsolid-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonYong%2Fsolid-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonYong%2Fsolid-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonYong%2Fsolid-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NelsonYong","download_url":"https://codeload.github.com/NelsonYong/solid-request/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246713085,"owners_count":20821836,"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-08-01T07:01:14.959Z","updated_at":"2025-04-01T21:31:20.102Z","avatar_url":"https://github.com/NelsonYong.png","language":"TypeScript","funding_links":[],"categories":["📦 Components \u0026 Libraries"],"sub_categories":["Helpers"],"readme":"# Solid-request\n\nWith a strong ability to manage network requests, Hook has a flying experience\n\n\u003cbr /\u003e\n\n## Usage\n\n### Install\n\n```bash\nnpm i solid-request\n```\n\n### Import\n\n```typescript\nimport useRequest from \"solid-request\";\n```\n\n`useRequest` Through the plug-in organization code, the core code is easy to understand, and can be easily expanded to more advanced functions. Capacity is now available to include\n\n- Automatic/manual request\n- Support Typescript\n- Polling\n- Debounce\n- Throttle\n- Refresh on window focus\n- Error retry\n- Loading delay\n- SWR(stale-while-revalidate)\n- Caching\n- Plugins\n\n## Default request\n\nBy default, the first parameter of `useRequest` is an asynchronous function, which is automatically executed when the component is initialized. At the same time, it automatically manages the status of `loading`, `data`, `error` of the asynchronous function.\n\n```js\nconst { data, error, loading } = useRequest(service);\n```\n\n## example\n\n```jsx\nexport async function getList({ id }: { id: number }): Promise\u003c{\n\tid: number\n\ttitle: string\n\tbody: string\n\tuserId: number\n}\u003e {\n\tconsole.log(id)\n\n\treturn fetch(`https://jsonplaceholder.typicode.com/posts/${id}`).then(\n\t\t(response) =\u003e response.json()\n\t)\n}\n\nfunction App() {\n\tconst [count, setCount] = createSignal(1)\n\n\tconst { data, loading } = useRequest(() =\u003e getList({ id: count() }), {\n\t\tmanual: false,\n\t\tready: true,\n\t\trefreshDeps: [count],\n\t})\n\n\treturn (\n\t\t\u003cdiv\u003e\n\t\t\t\u003cbutton type=\"button\" onClick={increment}\u003e\n\t\t\t\t{count()}\n\t\t\t\u003c/button\u003e\n\t\t\t\u003cdiv\u003e{loading() ? 'loading...' : JSON.stringify(data())}\u003c/div\u003e\n\t\t\u003c/div\u003e\n\t)\n}\n```\n\nThe document is under development, for more APIs, please see the vue version of [useRequest](https://inhiblabcore.github.io/docs/hooks/en/useRequest/)\n\n## Result\n\n| Property     | Description                                                                                                                                                                             | Type                                                                  |\n| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |\n| data         | Data returned by service                                                                                                                                                                | `Accessor\u003cTData \\| undefined\u003e` `                                      |\n| error        | Exception thrown by service                                                                                                                                                             | `Accessor\u003cError\u003e` \\| `undefined`                                      |\n| loading      | Is the service being executed                                                                                                                                                           | `Accessor\u003cboolean\u003e`                                                   |\n| params       | An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]`                                                   | `Accessor\u003cTParams \\| []\u003e`                                             |\n| run          | \u003cul\u003e\u003cli\u003e Manually trigger the execution of the service, and the parameters will be passed to the service\u003c/li\u003e\u003cli\u003eAutomatic handling of exceptions, feedback through `onError`\u003c/li\u003e\u003c/ul\u003e | `(...params: TParams) =\u003e void`                                        |\n| runAsync     | The usage is the same as `run`, but it returns a Promise, so you need to handle the exception yourself.                                                                                 | `(...params: TParams) =\u003e Promise\u003cTData\u003e`                              |\n| refresh      | Use the last params, call `run` again                                                                                                                                                   | `() =\u003e void`                                                          |\n| refreshAsync | Use the last params, call `runAsync` again                                                                                                                                              | `() =\u003e Promise\u003cTData\u003e`                                                |\n| mutate       | Mutate `data` directly                                                                                                                                                                  | `(data?: TData / ((oldData?: TData) =\u003e (TData / undefined))) =\u003e void` |\n| cancel       | Ignore the current promise response                                                                                                                                                     | `() =\u003e void`                                                          |\n\n## Options\n\n| Property      | Description                                                                                                                                                                                                     | Type                                                 | Default |\n| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ------- |\n| initialData   | Init data                                                                                                                                                                                                       | `TData` \\| `undefined`                               |         |\n| manual        | \u003cul\u003e\u003cli\u003e The default is `false`. That is, the service is automatically executed during initialization.\u003c/li\u003e\u003cli\u003eIf set to `true`, you need to manually call `run` or `runAsync` to trigger execution. \u003c/li\u003e\u003c/ul\u003e | `boolean`                                            | `false` |\n| defaultParams | The parameters passed to the service at the first default execution                                                                                                                                             | `TParams`                                            | -       |\n| formatResult  | Format the request results, which recommend to use `useFormatResult`                                                                                                                                            | `(response: TData) =\u003e any`                           | -       |\n| onBefore      | Triggered before service execution                                                                                                                                                                              | `(params: TParams) =\u003e void`                          | -       |\n| onSuccess     | Triggered when service resolve                                                                                                                                                                                  | `(data: TData, params: TParams) =\u003e void`             | -       |\n| onError       | Triggered when service reject                                                                                                                                                                                   | `(e: Error, params: TParams) =\u003e void`                | -       |\n| onFinally     | Triggered when service execution is complete                                                                                                                                                                    | `(params: TParams, data?: TData, e?: Error) =\u003e void` | -       |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNelsonYong%2Fsolid-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNelsonYong%2Fsolid-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNelsonYong%2Fsolid-request/lists"}