を反応させるのネイティブコンポーネントを反応させるのが、私はそうしようとすると、私は次のエラーを取得しています:エラーで、私は(特注)の配列をレンダリングしようとしているネイティブ
要素の型が無効です:文字列(組み込みコンポーネント用)またはクラス/関数(複合コンポーネント用)、got:オブジェクトが必要です。 'CategoryList'のレンダリングメソッドを確認してください。
Iは、(ステートレスコンポーネントである)CategoryList
と呼ばれる成分を有し、それはCategory
コンポーネントのコレクションをレンダリングします。これらは以下のように定義される:
CategoryList
:
import React, { PropTypes } from 'react';
import View from 'react-native';
import humps from 'humps';
import Category from './Category';
const CategoryList = ({ categories }) => {
const camelizedCategories = humps.camelizeKeys(categories);
const categoryElements = camelizedCategories.map(
(category, idx) => <Category {...category} key={idx} />
);
return (
<View>
{categoryElements}
</View>
);
};
CategoryList.propTypes = {
categories: PropTypes.arrayOf(
PropTypes.shape({
display_name: PropTypes.string.isRequired,
list_name: PropTypes.string.isRequired,
list_name_encoded: PropTypes.string.isRequired,
newest_published_date: PropTypes.string.isRequired,
oldest_published_date: PropTypes.string.isRequired,
updated: PropTypes.string.isRequired,
})
),
};
export default CategoryList;
Category
:
import React from 'react';
import { View, Text } from 'react-native';
const Category = ({
displayName,
listName,
listNameEncoded,
newestPublishedDate,
oldestPublishedDate,
updated,
}) => {
return (
<View>
<Text>
{displayName}
</Text>
<Text>
{listName}
{listNameEncoded}
</Text>
<Text>
{listNameEncoded}
</Text>
<Text>
{newestPublishedDate}
</Text>
<Text>
{oldestPublishedDate}
</Text>
<Text>
{updated}
</Text>
</View>
);
};
Category.propTypes = {
displayName: React.PropTypes.string.isRequired,
listName: React.PropTypes.string.isRequired,
listNameEncoded: React.PropTypes.string.isRequired,
newestPublishedDate: React.PropTypes.string.isRequired,
oldestPublishedDate: React.PropTypes.string.isRequired,
updated: React.PropTypes.string.isRequired,
};
export default Category;
次のように最後に、カテゴリが呼び出されている:
<CategoryList categories={mockedData} />
次のように
mockedData
が定義されている
:
const mockedData = [
{
list_name: 'Combined Print and E-Book Fiction',
display_name: 'Combined Print & E-Book Fiction',
list_name_encoded: 'combined-print-and-e-book-fiction',
oldest_published_date: '2011-02-13',
newest_published_date: '2016-08-21',
updated: 'WEEKLY',
},
{
list_name: 'Combined Print and E-Book Nonfiction',
display_name: 'Combined Print & E-Book Nonfiction',
list_name_encoded: 'combined-print-and-e-book-nonfiction',
oldest_published_date: '2011-02-13',
newest_published_date: '2016-08-21',
updated: 'WEEKLY',
},
];
?それでも同じエラーが出ますか? – nabn
Nabn、私はそれをしてもエラーはありません。 –