2017-10-10 1 views
-1

https://github.com/ScorpIan555/snapshotReact/projet Redux, promesse vide retourné de back-end via mon api

Voir ci-dessus repo, je compris que parce que je me bats pour expliquer de façon concise la question et le clonage, il pourrait être plus évident pour quelqu'un Sinon, à part le fait qu'aux lignes 10/lignes 11 de mon fichier actions/index.js (code ci-dessous), la promesse revient vide de l'API connectant mon front/backend. J'ai encore regardé mon backend, mais il a testé ok avant. Iv'e été et encore et ne peut tout simplement pas trouver le problème.

Laissez-moi savoir quelles questions les gens ont et je vais modifier ce poste en conséquence ...

Mon contenant Account.js:

import React, { Component } from 'react' 
import { Register } from '../view' 
import { connect } from 'react-redux' 
import actions from '../../actions' 

class Account extends Component { 

    register(registration){ 
     //this.props.signup(registration) 
     console.log('REGISTER: '+ JSON.stringify(registration)) 
     this.props.signup(registration) 
    } 

    render() { 

    return(
     <div> 
       Account Container 
       { 
      //(currentUser == null) ? 
      //<Register onRegister={this.register.bind(this)} onLogin={this.login.bind(this)} /> //: 
      //<Register /> //: 
      <Register onRegister={this.register.bind(this) } /> //: 
        //<h2>{currentUser.username}</h2> 
       } 

      </div> 
    ) 
    } 
}// class Account 

const stateToProps = (state) => { 
    return { 
    account: state.account + 
    console.log(JSON.stringify(state.account)) 
    } 
} 

const dispatchToProps = (dispatch) => { 
    return { 
    signup: (params) => dispatch(actions.signup(params)) 
    } 
} 
export default connect(stateToProps, dispatchToProps)(Account) 

L'accessoire d'inscription est une action définie dans mes actions/fichier index.js:

import constants from '../constants' 
import { APIManager } from '../utils' 

export default { 

    signup: (params) => { 
     console.log('post receive: ' +JSON.stringify(params)) 
     return (dispatch) => { 
      APIManager 
      .post('/account/register', params) 
      .then(response => { 
       console.log('RESPONSE : Actions index.js: '+JSON.stringify(response)) 
       dispatch({ 
        type: constants.CURRENT_USER_RECEIVED, 
        user: response.user 
       }) 
      })// .then(response => { 
      .catch((err) => { 
       console.log('ERROR: '+err) 
      })// .catch(err) 
     }// return (dispatch) 
    }, 

    updateCurrentLocation: (location) => { 
     return { 
      type: constants.CURRENT_LOCATION_CHANGED, 
      location: location 
     } 
    }, 

    createPost: (params) => { 
     return (dispatch) => { 
      APIManager 
      .post('/api/post', params) 
      .then(response => { 
       console.log('RESPONSE: '+JSON.stringify(response)) 

       // dispatch({ 
       // type: constants.POSTS_RECEIVED, 
       // posts: response.results 
       // }) 
      })//.then(response => { 
      .catch((err) => { 
       console.log('ERROR: '+err) 
      })// .catch(err) 
     }// return (dispatch) 
    }, 

    fetchPosts: (params) => { 
     return (dispatch) => { 
      APIManager 
      .get('/api/post', null) 
      .then(response => { 
       console.log('RESPONSE: '+JSON.stringify(response)) 
       dispatch({ 
        type: constants.POSTS_RECEIVED, 
        posts: response.results 
       }) 
      }) 
      .catch((err) => { 
       console.log('ERROR: '+err) 
      })// .catch(err) 
     }// return (dispatch) 
    },// fetchPosts, 

    postsReceived: (posts) => { 
     return { 
      type: constants.POSTS_RECEIVED, 
      posts: posts 
     } 

    }// postsReceived: 

}// export default 

Mes constantes fichier où CURRENT_USER_RECEIVED est défini:

export default { 

    CURRENT_USER_RECEIVED: 'CURRENT_USER_RECEIVED', 

    CURRENT_LOCATION_CHANGED: 'CURRENT_LOCATION_CHANGED', 

    POSTS_RECEIVED: 'POSTS_RECEIVED' 

} 

Mon magasin:

import { createStore, combineReducers, applyMiddleware } from 'redux' 
import thunk from 'redux-thunk' 
import { postReducer, accountReducer } from '../reducers' 

var store; 

export default { 
    configureStore:() => { 
     const reducers = combineReducers({ 
      post: postReducer, 
      account: accountReducer 
     }) 

     store = createStore(
      reducers, 
      applyMiddleware(thunk) 
     ) 

     return store 
    }, 

    currentStore:() => { 
     return store 
    } 
} 

accountReducer défini:

import constants from '../constants' 

var initialState = { 
    user: null 
} 

export default (state = initialState, action) => { 
    let updated = Object.assign({}, state) 

    switch (action.type){ 
    case constants.CURRENT_USER_RECEIVED: 
console.log('CURRENT_USER_RECEIVED reducer0 : ' + JSON.stringify(updated)) 
     console.log('CURRENT_USER_RECEIVED reducer1 : ' + JSON.stringify(action)) 
     console.log('CURRENT_USER_RECEIVED reducer2 : ' + JSON.stringify(action.username)) 

     updated['user'] = action.user 
     return updated 

     default: 
      return updated 

    } 
} 

Répondre

0

erreur stupide, mauvaise variable des ressources