聞きたいこと
React Nativeでstateで保持している配列の中の値をrenderメソッド内で表示したいと思っているのですが、下のようなエラーになってしまっています。
Invariant Violation: Objects are not valid as a React child
実際のコードはこちらです。
- App.js
import React, { Component } from 'react'; import { Text } from 'react-native'; export default class App extends Component{ constructor(props) { super(props); const data = [{'Tokyo': 'Shibuya'}, {'Osaka': 'Doutonbori'}]; this.state = { preferences: data } } render(){ // Shibuyaと表示させたい。 return( <Text>{this.state.preferences[0]['Tokyo']}</Text> ); } }
上記以外で実施したこと
this.state.preferences[0]['Tokyo']をreturn()の前で別の変数に代入し、その変数を表示するようにしたが同様のエラーになってしまった。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/21 14:36
2019/06/21 14:52
2019/06/21 15:05
2019/06/21 15:09
2019/06/21 15:40
2019/06/21 15:51