警告:不推荐使用ReactNative.createElement

时间:2016-05-17 22:35:11

标签: javascript reactjs react-native

我正在使用React Native创建简单的两个条形项目应用程序。 建成后我收到了这样的警告

Warning: ReactNative.createElement is deprecated. Use React.createElement from the "react" package instead.

因此,我没有看到任何标签图标。

这是我的代码:

'use strict';

var React = require('react-native');
var Featured = require('./Featured');
var Search = require('./Search');

var {
    AppRegistry,
    TabBarIOS,
    Component
   } = React;


class BookSearch extends Component {

    constructor(props) {
        super(props);
        this.state = {
            selectedTab: 'featured'
        };
    }

    render() {
        return (
            <TabBarIOS selectedTab={this.state.selectedTab}>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'featured'}
                    icon={{uri:'featured'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'featured'
                        });
                    }}>
                    <Featured/>
                </TabBarIOS.Item>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'search'}
                    icon={{uri:'search'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'search'
                        });
                    }}>
                    <Search/>
                </TabBarIOS.Item>
            </TabBarIOS>
        );
    }
}

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

我在这里浏览并发现,在最新版本中我应该使用类似的东西:

import React from 'react';

import {
    AppRegistry,
    TabBarIOS,
    Component
} from 'react-native';

但是,当我以这种方式重写代码时出现错误:

 Complex binding patterns require an initialization value (18:4) 

我该如何解决?

0 个答案:

没有答案