{"id":20556429,"url":"https://github.com/flagsmith/react-navigation-focus-render","last_synced_at":"2025-10-04T08:42:05.676Z","repository":{"id":57341767,"uuid":"461437145","full_name":"Flagsmith/react-navigation-focus-render","owner":"Flagsmith","description":"Wrapping components in this will ensure that they are only rendered when the screen is focused","archived":false,"fork":false,"pushed_at":"2022-02-20T16:09:16.000Z","size":470,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-29T00:46:22.418Z","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/Flagsmith.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}},"created_at":"2022-02-20T09:14:55.000Z","updated_at":"2024-08-23T10:13:29.000Z","dependencies_parsed_at":"2022-09-16T02:50:16.951Z","dependency_job_id":null,"html_url":"https://github.com/Flagsmith/react-navigation-focus-render","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Flagsmith/react-navigation-focus-render","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flagsmith%2Freact-navigation-focus-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flagsmith%2Freact-navigation-focus-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flagsmith%2Freact-navigation-focus-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flagsmith%2Freact-navigation-focus-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flagsmith","download_url":"https://codeload.github.com/Flagsmith/react-navigation-focus-render/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flagsmith%2Freact-navigation-focus-render/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278289234,"owners_count":25962348,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-16T03:27:42.641Z","updated_at":"2025-10-04T08:42:05.648Z","avatar_url":"https://github.com/Flagsmith.png","language":"TypeScript","readme":"[![react-navigation-focus-render](https://github.com/Flagsmith/flagsmith/raw/main/static-files/hero.png)](https://www.flagsmith.com/)\n\n# react-navigation-focus-render\n\nScreens within a stack or in tabs will still render when any global state(Redux/Context etc) is updated. This component lets you avoid these renders when the screens are inactive. \n\n\nRead a more in depth article about this [here](https://dev.to/kylessg/improving-your-react-native-application-performance-with-react-navigation-focus-render-2hih)\n\n\n\n# Installation\n\n``\nnpm i react-navigation-focus-render --save\n``\n\n# Usage\n\n```\nimport FocusRender from 'react-navigation-focus-render'\n\nconst ExpensiveComponent = () =\u003e {\n   const {count} = useCount(); // something that hooks into changing state\n   \n   return (\n     \u003cFocusRender\u003e\n       ... Components that will only re-render when the screen is focused\n     \u003c/FocusRender\u003e\n   ) \n}\n```\n\n# Advanced usage\n\nYou may wish to add a wrapper component that displays differently whilst the inactive component hydrates its state when the screen becomes active.\n\nYou can specify a Wrapper component that takes isFocused as a property.\n\n```\nimport FocusRender from 'react-navigation-focus-render'\n\nconst Wrapper = ({isFocused, children}) =\u003e (\n  \u003cView style={{opacity: isFocused ? 1 : 0.5}}\u003e{children}\u003c/View\u003e\n);\n\nconst ExpensiveComponent = () =\u003e {\n   const {count} = useCount(); // something that hooks into changing state\n   \n   return (\n     \u003cFocusRender Wrapper={Wrapper}\u003e\n       ... Components that will only re-render when the screen is focused\n     \u003c/FocusRender\u003e\n   ) \n}\n```\n\n# Example\n\nThis repository includes an [example project](/example) that demonstrates this working in a simple way.\n\n[HomeScreen](./example/app/components/screens/HomeScreen.tsx): \n\n- Contains an expensive component that renders 5000 text elements and is connected to redux state \"count\"\n- You can toggle between rendering the component via FocusRender or just by itself\n\n[Screen2](./example/app/components/screens/Screen2.tsx):\n\n- Contains a screen with a button that updates state \"count\"\n\n\nGiven this simple example, the difference in performance when updating state can be measured using [https://github.com/Flagsmith/react-native-performance-monitor](react-native-performance-monitor).\n\n\n![img.png](img.png)\n\nOf course, this is quite an extreme example but given an active stack of many tabs / screens this could easily add up if you have complex components.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflagsmith%2Freact-navigation-focus-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflagsmith%2Freact-navigation-focus-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflagsmith%2Freact-navigation-focus-render/lists"}