https://github.com/eveningkid/react-native-dynamic-styles
Dynamic stylesheet and styles for React Native
https://github.com/eveningkid/react-native-dynamic-styles
react-native style stylesheet
Last synced: 9 months ago
JSON representation
Dynamic stylesheet and styles for React Native
- Host: GitHub
- URL: https://github.com/eveningkid/react-native-dynamic-styles
- Owner: eveningkid
- License: mit
- Created: 2021-03-14T17:24:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-14T18:16:29.000Z (over 5 years ago)
- Last Synced: 2025-10-07T00:34:49.952Z (9 months ago)
- Topics: react-native, style, stylesheet
- Language: JavaScript
- Homepage:
- Size: 289 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-dynamic-styles
Dynamic stylesheet and styles for React Native.
```js
const [color, setColor] = useState('red');
// From unecessary style objects created at every render...
return ;
// ...to recreating a style object ONLY when dependencies have changed!
// And this time, it's not just an object but a StyleSheet reference instead :)
const style = useDynamicStyle(
() => ({
backgroundColor: color,
}),
[color]
);
return ;
```
⚡️ Generate optimized, dynamic styles just when you need it
⏩ Skip unecessary style object recreations
💅 Get `StyleSheet.create`d styles, even when they're dynamic
## Usage
```sh
npm install react-native-dynamic-styles
```
```js
import { useState } from 'react';
import { Button, Text, View } from 'react-native';
import { useDynamicStyle } from 'react-native-dynamic-styles';
export default () => {
const [opened, setOpened] = useState(false);
const toggle = () => setOpened(!opened);
const style = useDynamicStyle(
() => ({
flex: 1,
opacity: opened ? 1 : 0,
}),
[opened]
);
return (
<>
This will be our secret!
>
);
};
```
## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT © eveningkid