{"id":18331978,"url":"https://github.com/mrousavy/react-native-style-utilities","last_synced_at":"2025-05-02T22:31:05.557Z","repository":{"id":42382032,"uuid":"358554082","full_name":"mrousavy/react-native-style-utilities","owner":"mrousavy","description":"Fully typed hooks and utility functions for the React Native StyleSheet API","archived":false,"fork":false,"pushed_at":"2022-04-07T20:01:02.000Z","size":247,"stargazers_count":94,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-21T17:47:11.554Z","etag":null,"topics":["findstyle","library","native","react","registered","style","useflatstyle","usestyle","utilities","utils"],"latest_commit_sha":null,"homepage":"https://gist.github.com/mrousavy/0de7486814c655de8a110df5cef74ddc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrousavy.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-04-16T09:58:42.000Z","updated_at":"2025-02-16T15:32:37.000Z","dependencies_parsed_at":"2022-09-07T12:01:48.564Z","dependency_job_id":null,"html_url":"https://github.com/mrousavy/react-native-style-utilities","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/mrousavy%2Freact-native-style-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2Freact-native-style-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2Freact-native-style-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2Freact-native-style-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrousavy","download_url":"https://codeload.github.com/mrousavy/react-native-style-utilities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252116118,"owners_count":21697313,"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":["findstyle","library","native","react","registered","style","useflatstyle","usestyle","utilities","utils"],"created_at":"2024-11-05T19:36:40.900Z","updated_at":"2025-05-02T22:31:01.959Z","avatar_url":"https://github.com/mrousavy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003ereact-native-style-utilities\u003c/h1\u003e\n  \u003cp\u003eFully typed hooks and utility functions for the React Native StyleSheet API\u003c/p\u003e\n  \u003cbr /\u003e\n  \u003cpre align=\"center\"\u003enpm i \u003ca href=\"https://www.npmjs.com/package/react-native-style-utilities\"\u003ereact-native-style-utilities\u003c/a\u003e\u003c/pre\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n## ESLint Setup\n\nIf you're using the [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks) plugin, add the following to your `.eslintrc.js`:\n\n```js\n\"react-hooks/exhaustive-deps\": [\n  \"error\",\n  {\n    additionalHooks: \"(useStyle|useFlatStyle)\",\n  },\n],\n```\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## `useStyle`\n\nA hook to memoize dynamic styles.\n\n\u003e See [\"Memoize!!! 💾 - a react (native) performance guide\"](https://gist.github.com/mrousavy/0de7486814c655de8a110df5cef74ddc)\n\n### Objects\n\nBy using `useStyle` the object `{ height: number }` gets memoized and will only be re-created if `someDynamicValue` changes, resulting in **better optimized re-renders**.\n\n#### Bad\n\n```tsx\nreturn \u003cView style={{ height: someDynamicValue }} /\u003e\n```\n\n#### Good\n\n```tsx\nconst style = useStyle(() =\u003e ({ height: someDynamicValue }), [someDynamicValue])\n\nreturn \u003cView style={style} /\u003e\n```\n\n### Arrays\n\n`useStyle` can also be used to join arrays together, also improving re-render times.\n\n#### Bad\n\n```tsx\nreturn \u003cView style={[styles.container, props.style, { height: someDynamicValue }]} /\u003e\n```\n\n#### Good\n\n```tsx\nconst style = useStyle(\n  () =\u003e [styles.container, props.style, { height: someDynamicValue }],\n  [props.style, someDynamicValue]\n);\n\nreturn \u003cView style={style} /\u003e\n```\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## `useFlatStyle`\n\nSame as `useStyle`, but flattens (\"merges\") the returned values into a simple object with [`StyleSheet.flatten(...)`](https://reactnative.dev/docs/stylesheet#flatten).\n\n\u003e See [\"Memoize!!! 💾 - a react (native) performance guide\"](https://gist.github.com/mrousavy/0de7486814c655de8a110df5cef74ddc)\n\n```tsx\nconst style1 = useStyle(\n  () =\u003e [styles.container, props.style, { height: someDynamicValue }],\n  [props.style, someDynamicValue]\n);\nstyle1.borderRadius // \u003c-- does not work, `style1` is an array!\n\nconst style2 = useFlatStyle(\n  () =\u003e [styles.container, props.style, { height: someDynamicValue }],\n  [props.style, someDynamicValue]\n);\nstyle2.borderRadius // \u003c-- works, will return 'number | undefined'\n```\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## `findStyle`\n\nA helper function to find a given style property in any style object without using expensive flattening (no `StyleSheet.flatten(...)`).\n\n```tsx\nfunction Component({ style, ...props }) {\n  const borderRadius = style.borderRadius // \u003c-- does not work, style type is complex\n  const borderRadius = findStyle(style, \"borderRadius\") // \u003c-- works, is 'number | undefined'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Freact-native-style-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrousavy%2Freact-native-style-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Freact-native-style-utilities/lists"}