Naveen DINUSHKA
Naveen DINUSHKA

Reputation: 1627

Undefined is not object when importing StyleSheet from React Native

I am trying to use Expo to create an iOS app, but I'm getting an error when running on the device. Here's my App.js:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

const styles = React.StyleSheet.create({
    container: {
        paddingTop:40,
    },
});

class TaskList extends React.Component {
    render() {
        return (
            <View style = {styles.container}>
                <Text>Hi, This is  a TaskList!</Text>
            </View>
        )
    }

}
export default TaskList;

But I get the error saying:

'undefined is not an object' (evaluating '_react3.default.Stylesheet.create')

Upvotes: 0

Views: 1151

Answers (1)

Andrew Li
Andrew Li

Reputation: 57964

You're trying to access StyleSheet from React, which doesn't exist! You've already imported StyleSheet from the React Native module, just refer to it plainly:

const styles = StyleSheet.create({ //NOT React.StyleSheet
  container: {
    paddingTop:40,
  },
});

Upvotes: 2

Related Questions