export default class Slides extends React.Component {
renderSlides() {
return this.props.data.map((slide)=> {
return (
<View key={slide.text}>
<Text> {slide.text} </Text>
</View>
);
});
}
render() {
return (
<ScrollView
horizontal
style= {{ flex: 1 }}
>
{ this.renderSlides() }
</ScrollView>
);
}
}
答案 0 :(得分:0)
首先,您需要将数据传递给幻灯片组件
import React from 'react';
import { Text, View } from 'react-native';
import Slides from "../components/Slides";
const SLIDE_DATA = [ { text: 'Welcome to JobApp' }, { text: 'Use this to get a Job' }, { text: 'Set your location, then swipe away' } ]
export default class WelcomeScreen extends React.Component {
render() {
return(
<Slides data = {SLIDE_DATA}/>
);
}
}
您可以使用Slides组件中的this.props.data获取数据