2017-12-08 13 views
0

私はちょうどwoocommerce APIからサンプルプロダクトデータを取得しようとしています。反応ネイティブのwoocommerceプロダクトデータを取得できません

これは私のコードです:

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    Text, 
    View 
} from 'react-native'; 
import Api from './WooCommerce/Api.js' 

export default class FetchExample extends Component{ 
    constructor() { 
     super(); 

    } 
    render() { 
     return (
      <View> 
       <Text>{this.state.date.name}</Text> 

      </View> 
     ); 
    } 
    componentWillMount() { 
     this.setState.date = Api.get('products/122609') 


    } 
} 



AppRegistry.registerComponent('fetchExample',() => FetchExample); 

そして、ここではエラーです:

Error Message

答えて

1

あなたのコンストラクタの内部デフォルト値を使用して状態を初期化:

this.state = { date: '...' }; 

Th直接割り当てが予期しない動作につながるため、州の更新ロジックを直接割り当てからthis.setStateに変更してください。

this.setState({ date: Api.get('products/122609') });