I'm looking for some help on a function I'm working on which, captures events from socket changes (socket.io), everything works fine but, since I'm making use of spreaded props, I'd like to store the arrays coming through in to a single array.
what I have
const handlers = (...args) => {
const result = [args];
console.log(result);
}
socket.onAny(handlers);
//socket.on('posts', handler);
but I'd like to have the expected result:
Array[[{}], [{}], [{}]]
here is the end result
const [changes, setChanges] = useState([]);
//Check socket changes
useEffect(() => {
const result = []
const handlers = (...args) => {
result.push(args)
setReplies(result)
}
socket.onAny(handlers);
return () => socket.offAny(handlers);
//eslint-disable-next-line react-hooks/exhaustive-deps
}, []);