我得到了这个使用套接字的钩子设置
import { useEffect, useState, useRef, useContext } from 'react';
import useSocket from './useSocket';
export default useMarkers = () => {
const [markers, setMarkers] = useState([]);
const [socket] = useSocket();
useEffect(() => {
socket.on('all markers', allMarkers => {
setMarkers([...allMarkers]);
});
}, [setMarkers]);
const addMarker = marker => {
socket.emit('add marker', marker);
};
return [markers, addMarker];
};
然后我试图在我的其他钩子之一中调用 addMarker 函数,例如:
const [addMarker] = useMarkers();
addMarker(address);
...
但是,我收到一个错误:
addMarker is not a function. (In 'addMarker(address)', 'addMarker' is an instance of Array)
我在这里想念什么?
炎炎设计
慕田峪4524236
相关分类