-
Notifications
You must be signed in to change notification settings - Fork 333
How can I reflect membership state updates? #3029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @Liamandrew, can you try using our hook |
Hi @khushal87, thanks - Yes I've seen that hook and I am using it, but I think the problem is more basic than that. Currently I pass in the context channel like so: const { channel, setChannel } = useChatContext();
const membership = useChannelMembershipState(channel); Which is fine on the initial render. However, when the membership status is changed, I use This is because React essentially performs the following check: So my question is, what is the correct way to call |
Hi @Liamandrew , No - that should be correct. The thing is, as you pointed out this won't trigger a rerender implicitly because of 2 things:
But, let me circle back to the initial thing that is being done - you should not need to Additionally, if that's a no-go for you, you can also listen to WS events instead of re-querying every time; that should make things a lot smoother for you. If you absolutely need a full channel rerender for whatever reason whenever you business logic happens and you don't have another out, a workaround you can use is to pass a |
Hi,
I have a scenario where users can view channels they aren't a member of.
When viewing a channel they aren't a member of, I show a "Subscribe" button which should add themselves to the channel. Conversely, if they are a member of said channel then there is an "Unsubscribe" button which removes themselves from the channel.
To drive this logic to determine which button to show, I'm using
channel.state.membership?.status
. However, because I'm also using context to store the channel/thread (similar to this) between the Channel List and Channel Messages, then I need a way to reflect the membership change back to this context in order for the buttons to switch.For example, this is what my subscribe action looks like:
It seems that React ignores the
setChannel(nextChannel)
call because it deems there to be no change betweenchannel
andnextChannel
in this case (due to shallow comparison).So what I've had to do is add a hack to force the screen to re-render by extending the context such that I can force a re-render:
Is there a recommended way to do this that I'm missing, without needing this force update workaround?
The text was updated successfully, but these errors were encountered: