You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tiavina-mika
changed the title
How to apply dynamic styles with StyleSheet and get correct typing?
Dynamic styles with StyleSheet get an type error?
Jan 16, 2025
@tiavina-mika
The error occurs because StyleSheet.create tries to validate the style object, and it doesn't support functions as values.
In order to achieve dynamic nature you can do something like this
function App(): React.JSX.Element {
const value = 100;
return (
<View style={{height: value}}>
<Text>Hello</Text>
</View>
);
}
export default App;
Description
It's work with this approach:
I got this TypeScript error
Steps to reproduce
npm install
App.tsx
fileReact Native Version
0.76.6
Affected Platforms
Runtime - Web, Runtime - Android, Runtime - iOS, Runtime - Desktop, Build - MacOS, Build - Windows, Build - Linux
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/tiavina-mika/dynamic-styling-types-issue
Screenshots and Videos
The text was updated successfully, but these errors were encountered: