gpt4 book ai didi

javascript - Uncaught Error : A state mutation was detected between dispatches

转载 作者:行者123 更新时间:2023-11-30 15:33:19 57 4
gpt4 key购买 nike

我正在制作一个 React + Redux 应用程序,当我点击一个链接时我得到了这个

Uncaught Error: A state mutation was detected between dispatches, in the path `library.items.5.track.duration`. This may cause incorrect behavior. (http://redux.js.org/docs/Troubleshooting.html#never-mutate-reducer-arguments)
at invariant (browser.js:40)
at index.js:50
at index.js:208
at index.js:21
at Object.select (bindActionCreators.js:7)
at ListItem.handleTrackNameClick (ListItem.js:12)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:70)
at executeDispatch (EventPluginUtils.js:89)
at Object.executeDispatchesInOrder (EventPluginUtils.js:112)
at executeDispatchesAndRelease (EventPluginHub.js:44)

现在我明白这意味着什么了,这意味着我在某个地方有一些代码正在改变我的状态。我的 reducer 甚至没有被调用,唯一在点击时被调用的是:

handleTrackNameClick() {
this.props.select([
deepAssign({}, this.props.track)
]);
}

和select函数对应的是:

function playTracks(tracks) {
console.log('playing');
return {
type: PLAY_TRACKS,
tracks: deepAssign({}, tracks)
};
}

然后(在显示播放之后)我立即得到错误,reducer 从未被调用。这很奇怪,因为我不会在我的代码中的任何地方改变我的状态。我真的不知道要发布什么,所以如果您需要更多,请告诉我。 Here是完整的来源

编辑:playTrack 函数接收这样的参数:

[
{
"id":"8hAt8fvQomHt9ztV",
"name":"Bounce",
"duration":114226,
"artist":{
"id":"1MUjmFoDBQOk2vbO",
"name":"System of a Down"
},
"album":{
"id":"8B7MePC7rhglf7px",
"name":"Toxicity"
}
}
]

这是调用前的示例状态:

{
"routing":{
"locationBeforeTransitions":{
"pathname":"/app/library",
"search":"",
"hash":"",
"state":null,
"action":"POP",
"key":"oabgr1",
"query":{

},
"$searchBase":{
"search":"",
"searchBase":""
}
}
},
"toolbar":{
"playing":false,
"currentTime":0,
"viewType":"redux-app/view-types/THUMBNAILS",
"searchString":"",
"volume":1
},
"library":{
"items":[
{
"id":"mwgwHdOVamAz8wq0",
"track":{
"id":"mwgwHdOVamAz8wq0",
"name":"A Hopeful Transmission",
"duration":33000,
"artist":{
"id":"tL1YNNTaOLvYmHot",
"name":"Coldplay"
},
"album":{
"id":"3xYmTho9gpG5g4bs",
"name":"Mylo Xyloto"
}
}
},
{
"id":"NVcZ9spiBPSebv57",
"track":{
"id":"NVcZ9spiBPSebv57",
"name":"X",
"duration":118160,
"artist":{
"id":"1MUjmFoDBQOk2vbO",
"name":"System of a Down"
},
"album":{
"id":"8B7MePC7rhglf7px",
"name":"Toxicity"
}
}
},...
],
"loading":false,
"viewType":"LIST",
"viewScope":"TRACKS"
},
"sidebar":{
"libraries":[
{
"_id":"GaejiodsIlFRteGW",
"name":"Test",
"path":"/home/vinz243/.cassette/downloads"
}
]
},
"store":{
"query":"",
"results":{
"albums":[

],
"tracks":[

]
},
"releases":[

]
}
}

最佳答案

在取消注释大块代码以尝试找到它的来源之后,我的 API 似乎返回了一些值,这些值会导致持续时间为 NaN 值,乘以 1000 导致了这个问题

关于javascript - Uncaught Error : A state mutation was detected between dispatches,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41947811/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com