Uncaught Error: A state mutation was detected between dispatches
Uncaught Error: A state mutation was detected between dispatches
我正在制作一个 React + Redux 应用程序,当我点击 link
时我得到了这个
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)
现在我明白这意味着什么了,这意味着我在某个地方有一些代码正在改变我的状态。我的减速器甚至没有被调用,唯一在点击时被调用的是:
handleTrackNameClick() {
this.props.select([
deepAssign({}, this.props.track)
]);
}
和select函数对应:
function playTracks(tracks) {
console.log('playing');
return {
type: PLAY_TRACKS,
tracks: deepAssign({}, tracks)
};
}
然后(显示播放后)我立即得到错误,reducer 从未被调用。这很奇怪,因为我不会在我的代码中的任何地方改变我的状态。我真的不知道 post 还有什么,如果您需要更多,请告诉我。 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 次导致此问题
我正在制作一个 React + Redux 应用程序,当我点击 link
时我得到了这个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)
现在我明白这意味着什么了,这意味着我在某个地方有一些代码正在改变我的状态。我的减速器甚至没有被调用,唯一在点击时被调用的是:
handleTrackNameClick() {
this.props.select([
deepAssign({}, this.props.track)
]);
}
和select函数对应:
function playTracks(tracks) {
console.log('playing');
return {
type: PLAY_TRACKS,
tracks: deepAssign({}, tracks)
};
}
然后(显示播放后)我立即得到错误,reducer 从未被调用。这很奇怪,因为我不会在我的代码中的任何地方改变我的状态。我真的不知道 post 还有什么,如果您需要更多,请告诉我。 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 次导致此问题