Javascript 收到呼叫但不更改状态

Javascript 收到呼叫但不更改状态,javascript,reactjs,redux,Javascript,Reactjs,Redux,我会检查行动和减速器是否都被调用。它们都会被调用,但mapstatetoprops不会更改状态。也意味着action.tpye正在发生变化。我不明白为什么它不起作用,任何帮助都是感激的 这是我的减速机 const calling = (state={}, action) => { switch (action.type) { case 'CALLING_USER': return {type: action.type, callLoading: true, isCa

我会检查行动和减速器是否都被调用。它们都会被调用,但mapstatetoprops不会更改状态。也意味着action.tpye正在发生变化。我不明白为什么它不起作用,任何帮助都是感激的

这是我的减速机

const calling = (state={}, action) => {
  switch (action.type) {
    case 'CALLING_USER':
      return {type: action.type, callLoading: true, isCalling: true, friend: action.friendSocket}
    case 'ANSWERING_CALL':
      console.log("ANSWER CALL")
      return {type: action.type, callLoading: true, isCalling: true, friend: action.data.socket, offer: action.data.offer}
    case 'CALL_SUCCESS':
      return {
        isCalling: true,
        callLoading: false
      }
    case 'CALL_ERROR':
      return {
        callLoading: false,
        error: true,
        callErrorText: action.err,
      }
    default:
      return {isCalling: false}
  }
}

export default calling
行动

export const CALLING_USER = 'CALLING_USER'
function callingUser(friendSocket) {
  return {
    type: CALLING_USER,
    friendSocket
  }
}

export const ANSWERING_CALL = 'ANSWERING_CALL'
function answeringCall(data) {
  return {
    type: ANSWERING_CALL,
    data
  }
}
export const CALL_ERROR = 'CALL_ERROR'
function callError(err) {
  return {
    type: CALL_ERROR,
    err
  }
}

export function callSetup(friendSocket, dispatch) {
  console.log("IS THIS WORKING")
  console.log(dispatch)
  return function(dispatch) {
    console.log(dispatch)
    dispatch(callingUser(friendSocket))
  }
}

export function answerSetup(data) {
  console.log("ANSWER SETUP")
  return function(dispatch) {
    dispatch(answeringCall(data))
  }
}
这里叫它

import { answerSetup } from './Redux/Actions'
import store from './Redux/store'
import io from "socket.io-client";

export const startGlobalSockets = (mySocket) => {
  mySocket.on("gettingCalled", data => {
    console.log("GETTING CALLED SOCKET", data)
    store.dispatch(answerSetup(data))
  })
}
export default startGlobalSockets
它应该使这一说法成为事实

const mapStateToProps = (state) => ({
  user: state.session.user,
  calling: state.calling
})

const isVideo = (this.props.calling.isCalling ?
    <Grid style={{width:"100%", height: "100%"}} item sm={10}>
          <VideoScreen/>
    </Grid> :
    <Grid style={{height: '57em', overflow: 'auto'}} item sm={10}>
      <div className="parent">
          <Post/>
      </div>
    </Grid>)
...
export default withRouter(connect(mapStateToProps)(Home))
const-mapStateToProps=(state)=>({
用户:state.session.user,
呼叫:state.calling
})
const isVideo=(this.props.calling.isCalling?
:
)
...
使用路由器导出默认值(连接(mapStateToProps)(主)

我假设您没有按要求使用
connect
。您正在导入它,但我看不出您在哪里使用它。如果您发布整个代码片段,包括connect和MapStateTops以及mapDispatchToProps的使用,将会有所帮助。

我假设您没有按照要求使用
connect
。您正在导入它,但我看不出您在哪里使用它。如果您发布整个代码片段,包括使用connect和mapStateToProps以及mapDispatchToProps,将会有所帮助。

在您的示例中,
answerSetup
返回一个函数,该函数在内部调用
answeringCall
,而不是具有操作类型和负载的对象(如
answeringCall
)。除非你有一些像react thunk这样的处理函数的中间件,而且你有特殊的逻辑,我不明白为什么不直接在调用组件中使用
answeringCall

在您的示例中
answerSetup
返回一个函数,该函数在内部调用
answeringCall
,而不是具有操作类型和负载的对象(如
answeringCall
)。除非你有像react thunk这样的处理函数的中间件,并且你有特殊的逻辑,否则我不明白为什么不直接在你的调用组件中使用
answeringCall

你也可以共享MapStateTrops函数以及如何使用它。我的第一个猜测是,您忘记在使用该状态块的组件上使用react redux的connect函数。您也可以共享
MapStateTrop
函数吗?我添加了
MapStateTrops
,但事实并非如此。当我调用
callSetup
时,这一功能就起作用了。唯一的区别是,
callSetup
被react组件调用,而
answerCall
被数组函数调用。您还可以共享MapStateTrops函数以及如何使用它。我的第一个猜测是,您忘记在使用该状态块的组件上使用react redux的connect函数。您也可以共享
MapStateTrop
函数吗?我添加了
MapStateTrops
,但事实并非如此。当我调用
callSetup
时,这一功能就起作用了。唯一的区别是,
callSetup
被react组件调用,而
answerCall
被数组函数调用