Fix: mutate freeze object

This commit is contained in:
Dreamacro 2021-09-25 22:06:22 +08:00
parent 8404781106
commit c21d9937fa
2 changed files with 7 additions and 4 deletions

View File

@ -224,7 +224,7 @@ export default function Connections () {
const conn = data.find(c => c.id === drawerState.selectedID)?.original
if (conn) {
setDrawerState(d => {
d.connection = conn
d.connection = { ...conn }
if (drawerState.selectedID === latestConntion.current.id) {
d.connection.completed = latestConntion.current.completed
}

View File

@ -1,3 +1,4 @@
import produce from 'immer'
import { useState, useMemo, useRef, useCallback } from 'react'
import * as API from '@lib/request'
@ -39,9 +40,11 @@ class Store {
} else {
const connection = this.connections.get(id)
if (connection != null) {
connection.completed = true
connection.uploadSpeed = 0
connection.downloadSpeed = 0
this.connections.set(id, produce(connection, draft => {
draft.completed = true
draft.uploadSpeed = 0
draft.downloadSpeed = 0
}))
}
}
}