{"id":18401992,"url":"https://github.com/vimtor/nuclio-custom-react-hooks","last_synced_at":"2025-07-02T08:09:58.073Z","repository":{"id":104206854,"uuid":"282841234","full_name":"vimtor/nuclio-custom-react-hooks","owner":"vimtor","description":"Source code of custom react hooks at Nuclio Digital School","archived":false,"fork":false,"pushed_at":"2020-07-31T18:41:15.000Z","size":413,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-29T02:53:59.027Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://nuclio.school","language":"JavaScript","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/vimtor.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-27T08:41:21.000Z","updated_at":"2023-03-04T10:46:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d63b603-c996-44ad-bf1c-256b9e9115a3","html_url":"https://github.com/vimtor/nuclio-custom-react-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vimtor/nuclio-custom-react-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimtor%2Fnuclio-custom-react-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimtor%2Fnuclio-custom-react-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimtor%2Fnuclio-custom-react-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimtor%2Fnuclio-custom-react-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimtor","download_url":"https://codeload.github.com/vimtor/nuclio-custom-react-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimtor%2Fnuclio-custom-react-hooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263099715,"owners_count":23413624,"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-11-06T02:40:44.260Z","updated_at":"2025-07-02T08:09:58.041Z","avatar_url":"https://github.com/vimtor.png","language":"JavaScript","readme":"# nuclio-custom-react-hooks\nSource code of custom react hooks masterclass at [Nuclio Digital School](https://nuclio.school/?lang=en).\n\n![preview](https://i.imgur.com/6QV9vJi.gif)\n\n## Setup\n\n```shell script\ngit clone https://github.com/papeloto/nuclio-custom-react-hooks.git\ncd nuclio-custom-react-hooks\nyarn install\nyarn start\n```\n\n## Ideas\n\n- Even thought hooks are functions they behave differently\n- Hooks are subscriptions to events\n- Hooks have [rules](https://reactjs.org/docs/hooks-rules.html) like starting by _use_ or not calling them conditionally\n- We can define our custom hooks to encapsulate logic\n- If your custom hook doesn't use the built-in hooks, it is probably a function, not a hook.\n- We can use libraries like [axios](https://www.npmjs.com/package/axios) for making fetching easier\n\n## Tasks\n\nYou will find the solutions of these tasks in different branches.\n\n1. Add check feature with its according update request\n2. Use axios' [instances](https://github.com/axios/axios#creating-an-instance) to clean up requests\n3. Do proper error checking on request\n4. Trust the request and rollback if they don't succeed\n5. Refactor to React [context](https://kentcdodds.com/blog/how-to-use-react-context-effectively/) with its custom `useTasks` hook. \n\nThat way we can make our components more isolated. Going from this:\n\n```jsx\nexport const Controls = ({ onLoad, tasks }) =\u003e (\n    \u003cfooter\u003e\n        \u003cdiv\u003e\n            \u003cstrong\u003e{tasks.filter((task) =\u003e !task.completed).length}\u003c/strong\u003e tasks left.\n        \u003c/div\u003e\n        \u003cbutton onClick={onLoad}\u003eLoad More\u003c/button\u003e\n    \u003c/footer\u003e\n);\n```\n\nTo this:\n\n```jsx\nexport const Controls = () =\u003e {\n    const { tasks, loadMore } = useTasks();\n\n    return (\n        \u003cfooter\u003e\n            \u003cdiv\u003e\n                \u003cstrong\u003e{tasks.filter((task) =\u003e !task.completed).length}\u003c/strong\u003e tasks left.\n            \u003c/div\u003e\n            \u003cbutton onClick={loadMore}\u003eLoad More\u003c/button\u003e\n        \u003c/footer\u003e\n    );\n};\n```\n\n6. Use some cool react data fetching library such as [react-query](https://github.com/tannerlinsley/react-query) or [swr](https://github.com/vercel/swr)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimtor%2Fnuclio-custom-react-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimtor%2Fnuclio-custom-react-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimtor%2Fnuclio-custom-react-hooks/lists"}