react-native - undefined 不是对象(评估“data.length”)
问题描述
我对 react-native 很陌生。我刚刚做了一个小应用程序。我想添加一些图片作为应用程序的介绍。所以我添加了“react-native-app-intro-slider”模块。然后我收到以下错误。
undefined 不是对象(评估“data.length”)
那是我的app.js
。我不确定问题是什么。
import React, { Component } from 'react';
import { StyleSheet, View, Text, Image } from 'react-native';
import AppIntroSlider from 'react-native-app-intro-slider';
const slides = [
{
key: 's1',
text: 'Best Recharge offers',
title: 'Mobile Recharge',
image: require('./intro/(1).jpg'),
backgroundColor: '#20d2bb',
},
{
key: 's2',
title: 'Flight Booking',
text: 'Upto 25% off on Domestic Flights',
image: require('./intro/(2).jpg'),
backgroundColor: '#febe29',
},
{
key: 's3',
title: 'Great Offers',
text: 'Enjoy Great offers on our all services',
image: require('./intro/(3).jpg'),
backgroundColor: '#22bcb5',
},
];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
showRealApp: false,
};
}
_renderNextButton = () => {
};
_renderDoneButton = () => {
};
_onDone = () => {
this.setState({ showRealApp: true });
};
_onSkip = () => {
this.setState({ showRealApp: true });
};
_renderItem = ({ item }) => {
};
render() {
if (this.state.showRealApp) {
return (
<View>
<Text>aaaaa</Text>
</View>
);
} else {
return (
<AppIntroSlider
slides={slides}
renderItem={this._renderItem}
onDone={this._onDone}
showSkipButton={true}
onSkip={this._onSkip}
renderDoneButton={this._renderDoneButton}
renderNextButton={this._renderNextButton}
/>
);
}
}
}
如何修复此错误?请帮我。
解决方案
错误是:slides={slides}
必须data={slides}
。
固定代码:
import React, { Component } from 'react';
import { StyleSheet, View, Text, Image } from 'react-native';
import AppIntroSlider from 'react-native-app-intro-slider';
const slides = [
{
key: 's1',
text: 'Best Recharge offers',
title: 'Mobile Recharge',
image: require('./intro/(1).jpg'),
backgroundColor: '#20d2bb',
},
{
key: 's2',
title: 'Flight Booking',
text: 'Upto 25% off on Domestic Flights',
image: require('./intro/(2).jpg'),
backgroundColor: '#febe29',
},
{
key: 's3',
title: 'Great Offers',
text: 'Enjoy Great offers on our all services',
image: require('./intro/(3).jpg'),
backgroundColor: '#22bcb5',
},
];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
showRealApp: false,
};
}
_renderNextButton = () => {
};
_renderDoneButton = () => {
};
_onDone = () => {
this.setState({ showRealApp: true });
};
_onSkip = () => {
this.setState({ showRealApp: true });
};
_renderItem = ({ item }) => {
};
render() {
if (this.state.showRealApp) {
return (
<View>
<Text>aaaaa</Text>
</View>
);
} else {
return (
<AppIntroSlider
data={slides}
renderItem={this._renderItem}
onDone={this._onDone}
showSkipButton={true}
onSkip={this._onSkip}
renderDoneButton={this._renderDoneButton}
renderNextButton={this._renderNextButton}
/>
);
}
}
}
推荐阅读
- jboss-eap-7 - 无法在我的 JBoss 7 上部署最小应用程序
- python - 如何在 google colab 中动态(循环)显示图像?
- web - 避免将图像发送给网站中的无关人员
- scala - 如何将构建器模式转换为功能实现?
- c++ - 关于 websocketpp 销毁的堆栈跟踪的困惑
- ruby - 为什么我无法在 Ruby 中访问哈希?
- c# - 如何强制填充控制器的 TempData?
- tfs - 包含美元符号的参数字符串
- swift - Auto-Size UITableViewCell 的内部 UITableView
- javascript - Vue数组,获取完整数组作品,数组中的特定项目未定义