問題)React renderから条件判定によりhmltタグをとってくる処理をPromiseで
やりたいのですがhtmlタグではなくObjectが返ってきてしまい以下のエラーが発生してしまう。
Promiseを使わなければ正常に動作するが、Promise.jsが使えないと今後の実装に非常に大きな制約が生じてしまうため何とか解決したい。
詳細)Promise.jsの使い方は正しいと思うのですが、なぜかPromise内のreturn htmlTagがHTMLタグではなくオブジェクトとして返ってきてしまう
エラー内容)render return内でオブジェクトの展開はできない旨のエラーメッセージ
Invariant Violation: Object are not valid as a React child (found: object with keys {fc4knr35wmi, _state, _result, _subscribers}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of 'KurasuA'.
問題のコード)
import React, {Component} from 'react'; import {Promise} from 'es6-promise'; export default class KurasuA extends Component { constructor (props) { super (props); this.hanteiFunc = this.hanteiFunc.bind (this); this.yobidasiFunc = this.yobidasiFunc.bind (this); }; damiFunc () { ・・・ }; yobidasiFunc () { return new Promise ( (resolve, reject) => { ・・・ let htmlTag = <a>・・・</a>; resolve (htmlTag); }; hanteiFunc () { if (・・・) { ・・・ } else { let yobidasiVar return this.yobidasiFunc (yobidasiVar) .then ( (result) => { return new Promise ( (resolve, reject) => { resolve (result); }); }).then ( (result) => { return result; }); } }; render () { return ( <div> {this.state.dottoejssaito === 'syousai' ? this.damiFunc() : this.hanteiFunc()} </div> ); }; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/10 11:10