原代码:
//socket
useEffect(()=>{
if(listId){
window.Echo.channel(`productconfig-list-info-results-${listId}`)
.listen('.ProductConfigListInfoResults', (res) => {
if(res){
// console.log(res,'socket listinfo')
getProjectFn(res.id,listType,listTitle,1,10)
}else{
}
})
}
},[listId])
现代码:
useEffect(() => {
if (listId) {
const channel = window.Echo.channel(`productconfig-list-info-results-${listId}`);
const handleSocketEvent = (res) => {
if (res && res.id) {
const debouncedGetProjectFn = debounce(() => {
getProjectFn(res.id, 'ProductConfig ', listTitle, 1, 10);
}, 500);
debouncedGetProjectFn();
}
};
channel.listen('.ProductConfigListInfoResults', handleSocketEvent);
return () => {
channel.stopListening('.ProductConfigListInfoResults', handleSocketEvent);
};
}
}, [listId, listTitle]);
解决之后