FourSquare APIに対して、YYYYMMDDの形式で送信される時間オブジェクトが必要なリクエストを作成しようとしています。私は時間オブジェクトを生成する関数を書いていますが、私はReactアプリケーション内でそれを使用する際に問題があります。コンポーネントライフサイクルAPIリクエストの返信
私は私のProfile
コンポーネント内で呼び出します
'use strict'
import React, { Component } from 'react'
import request from 'superagent'
import TimeService from './services/time'
import config from './config'
class Profile extends Component {
componentDidMount() {
TimeService.getCurrentTime((err, currentDate) => {
this.setState({
time: currentDate
})
})
}
componentWillMount() {
let currentTime = this.state.time
let venue = '4dd64e9de4cd37c8938e7b83'
//let venue = this.props.venueId
let clientId = config.CLIENT_ID
let clientSecret = config.CLIENT_SECRET
request.get(`https://api.foursquare.com/v2/venues/${venue}/hours/?\&client_id=${clientId}&client_secret=${clientSecret}&v=${currentTime}`)
.accept('json')
.end((err, res) => {
if(err) return
let result = res.body
console.log(res.body)
console.log(result.response.hours.timeframes)
})
}
私はChromeでアプリをロードすると、私はのエラーメッセージを持っている:bundle.js:44492 Uncaught TypeError: Cannot read property 'time' of null
は私の推測では、私は再注文機能する必要があることですしかし、コンポーネントの実装方法の中で、私はどのようにわかりません。
リアクションライフサイクルメソッドからデータを取得することに関連した、多くの類似した競合条件を処理しました。最終的には、開発者がそのことについて考える必要がないように、libに抽象化することに決めました。https://github.com/DigitalGlobe/jetset – glortho