You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to update a global redux state with pubnub events, but cannot, as the event listener does not recognize a redux-based global state variable even though, oddly, it can update the state. Here's my pseudo-code:
constMyComponent=()=>{const{messages}=useSelector(state=>state.chatstore)constdispatch=useDispatch();useEffect(()=>{pubnub.subscribe(channels)pubnub.addEventListener(pubnubListener)},[pubnub,channels])constpubnubListener=event=>{const{message}=eventconsole.log(messages)// returns nothing! I can't do any logic here related to all accumulated messagesdispatch({type: ADD_MESSAGE,message: newMessage})// This works, and...// ...I can do something with all messages within the reducer after dispatching}return(<div>{messages.map(message=><pkey={message.id}>{message}</p>)}</div>)}
The text was updated successfully, but these errors were encountered:
I'm trying to update a global redux state with pubnub events, but cannot, as the event listener does not recognize a redux-based global state variable even though, oddly, it can update the state. Here's my pseudo-code:
The text was updated successfully, but these errors were encountered: