@
ooo4 如果不加这个 currentChatId 可以满足你的功能,非要用 useEffect 的话,可以考虑一下用 useReducer 组织状态
```typescript
import React, {useEffect, useReducer, useState} from "react"
type Conversation = {
id:string
title:string
[key:string]:unknown
}
const initialState:Conversation[] = [
{id:'1',title:"title-1"},
{id:'2',title:"title-2"},
{id:'3',title:"title-3"},
]
function App() {
const [currentChatId,setCurrentChatId] = useState("")
const [currentChatTitle,setCurrentChatTitle] = useState("")
const [conversation,setConversation] = useReducer<
React.Reducer<
Conversation[],
(prev:Conversation[],curChatId:typeof currentChatId)=>Conversation[]
>
>((prev,action)=>{
console.log(123)
return action(prev,currentChatId)
},initialState)
useEffect(()=>{
if(currentChatTitle){
setConversation((prev,curChatId)=>{
console.log({curChatId})
return prev.map(i=>{
return {
...i,
title:
i.id === curChatId ? currentChatTitle : i.title,
}
})
})
}
},[currentChatTitle])
return <div>
<label htmlFor="currentChatId">currentChatId:</label>
<input type="text" id="currentChatId" value={currentChatId} onChange={(e)=>setCurrentChatId(e.target.value)} />
<label htmlFor="currentChatTitle">currentChatTitle:</label>
<input type="text" id="currentChatTitle" value={currentChatTitle} onChange={(e)=>setCurrentChatTitle(e.target.value)} />
<ul>
{
conversation.map(i=>{
return <li key={
i.id}>{i.title}</li>
})
}
</ul>
</div>
}
export default App;
```