Open
Description
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:
const MyComponent = () => {
const {messages} = useSelector(state => state.chatstore)
const dispatch = useDispatch();
useEffect(() => {
pubnub.subscribe(channels)
pubnub.addEventListener(pubnubListener)
}, [pubnub, channels])
const pubnubListener = event => {
const {message} = event
console.log(messages) // returns nothing! I can't do any logic here related to all accumulated messages
dispatch({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 => <p key={message.id}>{message}</p>)}
</div>
)
}
Metadata
Metadata
Assignees
Labels
No labels