【问题标题】:React-Native Code doesnt executeReact-Native 代码不执行
【发布时间】:2018-02-23 21:02:21
【问题描述】:

我找不到这里有什么问题:https://hastebin.com/fuwofavuso.scala(我不能在这里发布,我不想缩进所有行)。

import React, { Component} from 'react';
import { Text, View, StyleSheet, Image, TextInput, AppRegistry} from 'react-native';
import { Constants, BlurView } from 'expo';

export default class App extends Component {
  render() {
    return (
      <View style={{ height: 200, width: 300 }}>
        <InputText/>
      </View>
    );
  }
}

class InputText extends Component {
  constructor(props) {
    super(props);

    this.state = {
      text: 'lel',
    };
  }

  render() {
    return (
      <div>
        <TextInput
          onChangeText={(text) => this.setState({ text })}
          value={this.state.text}
        />
        <Text value={this.state.text}></Text>
      </div>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
    color: '#34495e',
  },
});
AppRegistry.registerComponent('Unknown Snack', () => InputText);

我的错误是:

undefined 不是评估 _reactnative.appregistry.registerComponent() 的对象

我在 Expo Snack 上运行它

【问题讨论】:

  • “不想缩进所有行” – 突出显示代码并单击一个按钮太费力了?
  • 你是如何运行它的?
  • 诚实的忠告;当向别人寻求帮助时,你应该付出你期望得到的回报的尽可能多的努力。您已将代码粘贴在链接后面,并且没有说明您已尝试解决此问题。所以我会给你一个同样努力的答案; “看起来您导入的 AppRegistry 组件不起作用”。
  • 请上传您的完整代码,我找不到您在哪里使用appregistry.registerComponent()
  • @VahidBoreiri 它也不适用于...

标签: reactjs react-native


【解决方案1】:

如您所见hereregisterComponent 函数有两个参数,第二个参数是您的主要组件,在您的情况下组件的名称似乎是错误的(您的问题可能是因为这个)。我认为你的代码应该是这样的:

AppRegistry.registerComponent('yourAppKey', App);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 2019-11-16
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多