gpt4 book ai didi

javascript - React Native - 不变违规

转载 作者:行者123 更新时间:2023-11-30 20:41:08 25 4
gpt4 key购买 nike

所以我构建了一个 Spinner 组件,但我不断遇到 Invariant Violation。

组件:

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

const Spinner = ({ size }) => {
return (
<View style={ styles.spinnerStyle }>
<ActivityIndicator size={ size || 'large' } />
</View>
);
};

const styles = {
spinnerStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
};

export { Spinner };

我在这里使用它:

// Import libs
import React, { Component } from 'react';
import { ScrollView } from 'react-native';
import Axios from 'axios';
import AlbumDetail from './albumDetail';
import { Spinner } from './common';

// Create component
class AlbumList extends Component {
state = {
albums: [],
loading: true
}

componentWillMount() {
Axios.get('xxxxx.json').then(response =>
this.setState({
albums: response.data,
loading: false
})
);
}

renderAlbums() {
if ( this.state.loading ) {
return <Spinner size='small'></Spinner>
}

return this.state.albums.map( album =>
<AlbumDetail key={album.title} album={album}/>
)
}

render() {
return (
<ScrollView>
{this.renderAlbums()}
</ScrollView>
);
}
}

// Export the component for the rest to use
export default AlbumList;

完整的错误是:Invariant Violation:Element type is invalid: expected a string.

我试过只添加:

if ( this.state.loading ) {
return (
<View style={styles.loading}>
<ActivityIndicator size='large' />
</View>
)
}

那行得通。但是当它作为一个组件使用时它不想玩。任何帮助都会很棒。谢谢

最佳答案

公共(public)文件夹中的索引没有:

从 './spinner' 导出 *;

关于javascript - React Native - 不变违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49254781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com