{"id":15805367,"url":"https://github.com/playpauseandstop/react-sadness","last_synced_at":"2026-01-11T22:59:20.166Z","repository":{"id":39328046,"uuid":"249231314","full_name":"playpauseandstop/react-sadness","owner":"playpauseandstop","description":"useRequest hook \u0026 set of components for requesting API data within React applications","archived":false,"fork":false,"pushed_at":"2023-01-06T02:42:21.000Z","size":2313,"stargazers_count":0,"open_issues_count":33,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T02:20:17.120Z","etag":null,"topics":["api","api-client","axios","react","react-library","reactjs"],"latest_commit_sha":null,"homepage":"https://react-sadness.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/playpauseandstop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-22T17:04:14.000Z","updated_at":"2021-09-01T19:56:02.000Z","dependencies_parsed_at":"2023-02-05T03:31:26.286Z","dependency_job_id":null,"html_url":"https://github.com/playpauseandstop/react-sadness","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playpauseandstop%2Freact-sadness","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playpauseandstop%2Freact-sadness/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playpauseandstop%2Freact-sadness/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playpauseandstop%2Freact-sadness/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/playpauseandstop","download_url":"https://codeload.github.com/playpauseandstop/react-sadness/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246547371,"owners_count":20794970,"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":["api","api-client","axios","react","react-library","reactjs"],"created_at":"2024-10-05T02:20:28.596Z","updated_at":"2026-01-11T22:59:20.153Z","avatar_url":"https://github.com/playpauseandstop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-sadness\n\n[![CI Workflow](https://github.com/playpauseandstop/react-sadness/workflows/ci/badge.svg)](https://github.com/playpauseandstop/react-sadness/actions?query=workflow%3A%22ci%22)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)](https://github.com/pre-commit/pre-commit)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![npm version](https://img.shields.io/npm/v/react-sadness)](https://www.npmjs.com/package/react-sadness)\n[![npm license](https://img.shields.io/npm/l/react-sadness)](https://www.npmjs.com/package/react-sadness)\n\n`useRequest` hook \u0026 set of components for requesting API data within React applications.\n\n- Built on top of [axios](https://github.com/axios/axios)\n- Supports prerendering\n- Provides common components for API needs\n\n## Requirements\n\n- [axios](https://github.com/axios/axios) 0.21 or later\n- [React](https://reactjs.org) 16.13 or later\n\n## Installation\n\n```bash\nnpm install axios react react-dom react-sadness\n```\n\n**IMPORTANT:** You need to install `axios`, `react` \u0026 `react-dom` in your project additionally, as they listed as **peer** dependencies to `react-sadness`. Installing just `react-sadness` will not be enough.\n\n## Quickstart\n\nFirst, you need to wrap your app container into the `SadnessProvider` \u0026 `mount` it into the DOM element (instead of `render` or `hydrate`),\n\n```jsx\nimport React from \"react\";\nimport { mount, SadnessProvider } from \"react-sadness\";\nimport { BrowserRouter } from \"react-router\";\n\nmount(\n  \u003cSadnessProvider\u003e\n    \u003cAppContainer /\u003e\n  \u003c/SadnessProvider\u003e,\n  document.getElementById(\"ui\")\n);\n```\n\nNext, to request data from the API anywhere inside of `AppContainer`,\n\n```jsx\nimport I from \"immutable\";\nimport React from \"react\";\nimport { Response, useRequest } from \"react-sadness\";\n\nimport { toUser } from \"../records/User\";\n\nconst toList = (data) =\u003e new I.List(data.map(toUser));\n\nconst Users = () =\u003e {\n  const { state } = useRequest(\"/users\", { responseDataConverter: toList });\n  return (\n    \u003cResponse state={state}\u003e\n      {(users) =\u003e (\n        \u003cul\u003e\n          {users.map((item) =\u003e (\n            \u003cli key={item.id}\u003e{item.username}\u003c/li\u003e\n          ))}\n        \u003c/ul\u003e\n      )}\n    \u003c/Response\u003e\n  );\n};\n```\n\n### Prerendering\n\n**IMPORTANT:** Example below illustrates prerendering data with [parcel-plugin-prerender](https://www.npmjs.com/package/parcel-plugin-prerender) plugin.\n\n`react-sadness` supports prerendering by triggering `readyEvent` via `SadnessReady` HoC.\n\n```jsx\nimport { SadnessReady } from \"react-sadness\";\n\nconst App = () =\u003e (\n  {/* Ready event will trigger after both child requests will done */}\n  \u003cSadnessReady\u003e\n    {/* Request projects from API */}\n    \u003cProjects /\u003e\n    {/* Request talks from API */}\n    \u003cTalks /\u003e\n  \u003c/SadnessReady\u003e\n)\n```\n\nAfterwards, you need to setup `parcel-plugin-prerender` to wait before `readyEvent`, such as,\n\n```json\n  \"prerender\": {\n    \"rendererConfig\": {\n      \"renderAfterDocumentEvent\": \"react-sadness-ready\"\n    }\n  }\n```\n\nIn case if children nodes does not contain any planned API requests, pass `force` prop to `SadnessReady` component to force triggering ready event,\n\n```jsx\nconst About = () =\u003e (\n  \u003cSadnessReady force\u003e\n    \u003cAboutContent /\u003e\n  \u003c/SadnessReady\u003e\n);\n```\n\n## Examples\n\nVisit [react-sadness.vercel.app](https://react-sadness.vercel.app) to browse through `react-sadness` Storybook.\n\nOr run,\n\n```bash\nmake run\n```\n\nto start Storybook server at `http://localhost:6006`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaypauseandstop%2Freact-sadness","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplaypauseandstop%2Freact-sadness","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaypauseandstop%2Freact-sadness/lists"}