2016-09-15 2 views
1

New React-Native. Я пытаюсь настроить его. В index.ios.js, у меня есть:React-Native - Невозможно найти переменную: title

class thingy extends Component { 
    render() { 
    return (
     <NavigatorIOS 
     style={styles.container} 
     initialRoute={(
      title: 'Thingy', 
      component: Main 
     )} /> 
    ); 
    } 
} 

Когда я запускаю это, приложение дает мне ошибку:

Не удается найти переменную: название

я не уверен, почему это дает мне эту ошибку. Есть идеи?

Главный компонент:

var React = require('react-native'); 

var { 
    View, 
    Text, 
    StyleSheet 
} = React; 

var styles = StyleSheet.create({ 
    mainContainer: { 
    flex: 1, 
    padding: 30, 
    marginTop: 65, 
    flexDirection: 'column', 
    justifyContent: 'center', 
    backgroundColor: '#48BBEC' 
    }, 
    title: { 
    marginBottom: 20, 
    fontSize: 25, 
    textAlign: 'center', 
    color: '#fff' 
    }, 
    searchInput: { 
    height: 50, 
    padding: 4, 
    marginRight: 5, 
    fontSize: 23, 
    bordderWidth: 1, 
    borderColor: 'white', 
    borderRadius: 8, 
    color: 'white' 
    }, 
    buttonText: { 
    fontSize: 18, 
    color: '#111', 
    alignSelf: 'center' 
    }, 
    button: { 
    height: 45, 
    flexDirection: 'row', 
    backgroundColor: 'white', 
    borderColor: 'white', 
    borderWidth: 1, 
    bordeRadius: 8, 
    marginBottom: 10, 
    marginTop: 10, 
    alignSelf: 'stretch', 
    justifyContent: 'center' 
    }, 
}); 

class Main extends React.Component{ 
    render(){ 
    return (
     <View style={styles.mainContainer}> 
     <Text> Testing the Router </Text> 
     </View> 
    ) 
    } 
}; 

module.exports = Main; 
+0

Можете ли вы показать свой код компонента «Главная»? –

+0

Сейчас там. – user1072337

ответ

1

Ах, это выглядит как initialRoute должен быть объектом, но вы его заворачивают в круглых скобках:

Как сейчас:

initialRoute={(
    title: 'Thingy', 
    component: Main 
)} 

На самом деле должно быть:

initialRoute={{ 
    title: 'Thingy', 
    component: Main 
}} 
+0

Этот новый синтаксис с ES6? – user1072337

+0

На самом деле, сейчас он говорит, что не может найти Главное ... – user1072337

+1

Я должен был потребовать его, неважно. – user1072337

Смежные вопросы