【问题标题】:React native error code syntax反应本机错误代码语法
【发布时间】:2016-10-25 04:58:26
【问题描述】:
import React, { Component } from 'react';
import {
    AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} from 'react-native';

import Button from '@remobile/react-native-simple-button';
import ImagePicker from '@remobile/react-native-image-picker';
import Dialogs from '@remobile/react-native-dialogs';

class cordovaReactImagePicker extends Component{
    onOpen() {
        var options = {maximumImagesCount: 10, width: 400};
        ImagePicker.getPictures(options, function(results) {
            var msg = '';
            for (var i = 0; i < results.length; i++) {
                msg += 'Image URI: ' + results[i] + '\n';
            }
            Dialogs.alert(msg);
        }, function (error) {
            Dialogs.alert('Error: ' + error);
        });
    }
    render() {
        return (
            <View style={styles.container}>
                <Button onPress={this.onOpen}>Photo</Button>
            </View>
        );
    }

};


var styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'transparent',
    },
});

AppRegistry.registerComponent('cordovaReactImagePicker', () => cordovaReactImagePicker);

我不断收到错误“似乎您正在尝试从 'react-native' 包访问 'Reactnative.createClass'。有人可以根据我的理解指导我应该如何做吗?是因为 react native sdk 语法代码已经改变了为什么它无法理解旧代码语法?任何帮助将不胜感激

【问题讨论】:

    标签: react-native


    【解决方案1】:

    与您使用的第三方库相比,您的 react-native 版本是最新的,因此出现此错误是因为第三方库是由较旧的 react native 语法制成的。因此,如果您的第三方库没有那么复杂,那么您可以在 node-modules 文件夹中使用它并将 React.createclass 更改为最新语法,否则您的第三方库应该由库的特定所有者更新

    如果你真的想使用那个库,你也可以在你的项目中使用旧版本的 RN https://stackoverflow.com/a/37623531/1868008

    【讨论】:

    • 感谢您的信息,我稍后会尝试,但如果是最新的 react native 版本,我应该如何编写 react native 语法代码以使其正常工作?
    • 您应该更改 node_modules 文件夹中某些库文件的一些语法,否则您应该创建一个未解决的问题来更新特定库 git 地址中的库。
    • 我明白了,感谢 Susyl 提供的信息,非常感谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 2019-02-18
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多