0

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
chackerian
  • 1,301
  • 2
  • 15
  • 29

2 Answers2

1

Declare the StyleSheet outside of the component.

const styles = StyleSheet.create({
  ...
});

class NewComponent extends React. Component {
  ...
Abe
  • 4,500
  • 2
  • 11
  • 25
0

import React, { Component } from "react";
import { StyleSheet } 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,
  },
})