前提・実現したいこと
https://qiita.com/YutamaKotaro/items/0521d83049536e451f15
上記のサイトを参考にToDoリストを作成しました。
そのToDoリストにHeaderを追加したかったので
App.js
を以下のように書き換え
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, View, FlatList, Text, } from 'react-native'; import Header from './src/component/Header'; import CommentIndex from './CommentIndex'; export default class app extends Component<Props> { render() { return ( <View style={styles.top}> <Header /> <CommentIndex /> </View> ); } } const styles = StyleSheet.create({ top: { paddingTop: 40, }, });
作成したToDoリストとHeaderを以下のようにして実装しようと考えました。
<Header /> <CommentIndex />
ですが、Headerは実装できるのですが、ToDoリストの方は実装出来ません。
inportのパスなどは間違って無いかと思います。
要素の取得からまたさらに要素の取得を行うことは出来ないのでしょうか?
よろしくお願いします。
CommentIndex.js
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, FlatList, } from 'react-native'; import CommentInput from './src/component/CommentInput'; import CommentItem from './src/component/CommentItem'; export default class CommentIndex extends Component<{}> { constructor(props) { super(props); this.state = { list: [], }; } _onPress = (text) => { const list = [].concat(this.state.list); list.push({ key: Date.now(), text: text, done: false, }); this.setState({ list, }); } render() { const { list, } = this.state; return ( <View style={styles.container}> <Text>あなたの仲間の行動を紹介しよう</Text> <View style={styles.main}> <CommentInput onPress={this._onPress} /> <View style={styles.CommentListContainer}> <FlatList style={styles.CommentList} data={list} renderItem={({ item }) => <CommentItem {...item} />} /> </View> </View> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#333', paddingTop: 40, alignItems: 'center', }, main: { flex: 1, maxWidth: 400, alignItems: 'center', }, CommentListContainer: { flexDirection: 'row', flex: 1, }, CommentList: { paddingLeft: 10, paddingRight: 10, } });
src/component/Header.js
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from "react"; import { Text, View, StyleSheet, } from 'react-native'; export default class Header extends Component<Props> { render() { return ( <View style={styles.header}> <Text style={styles.headerText}>Welcome to React Native!</Text> </View> ); } } const styles = StyleSheet.create({ header: { backgroundColor: '#F8F8F8', justifyContent: 'center', alignItems: 'center', height: 60, paddingTop: 15, elevation: 2, position: 'relative' }, headerText: { fontSize: 20, fontWeight: '600' }, });
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。