Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I'm trying to use React Native's Stylesheet.create method in class component and I'm getting an error. This does work in functional components but not in class components. How can I resolve this issue?
Declare the StyleSheet outside of the component.
const styles = StyleSheet.create({ ... }); class NewComponent extends React. Component { ...
Add a comment
import React, { Component } from "react"; import { StyleSheet, View } from 'react-native'; class App extends React.Component { render(){ return ( <View style={styles.container}> </View> ) } }; export default App; const styles = StyleSheet.create({ container: { flex: 1, }, })
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.