https://github.com/ScorpIan555/snapshotは/ Reduxのプロジェクト反応して、空の約束は私のAPIを介してバックエンドから返される
上記のレポは、私は簡潔に問題を説明するのに苦労し、クローニングしていますので、それが誰かのために、より明白であるかもしれないことを含め参照してください。そうでなければ、私のactions/index.jsファイル(以下のコード)の10行目/ 11行目で、私のフロントエンド/バックエンドを接続しているAPIから約束が空に戻ります。私はバックエンドをもう一度見ていましたが、以前はOKでした。 Iv'eはこれを何度も繰り返してきており、問題を見つけることができません。
私は、人々が持っていると私はそれに応じてこの記事を編集します問いかけるものを知ってみましょう...
マイ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)
サインアップ小道具/私のアクションで定義されたアクションです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
私の定数は、ファイルCURRENT_USER_RECEIVEDが定義されています
export default {
CURRENT_USER_RECEIVED: 'CURRENT_USER_RECEIVED',
CURRENT_LOCATION_CHANGED: 'CURRENT_LOCATION_CHANGED',
POSTS_RECEIVED: 'POSTS_RECEIVED'
}
マイストア:
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が定義:
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
}
}