2024-4-5
-
before a channel connects,
data
is nowundefined
rather thannull
-
basic
useEvent
data cachingThe last response from any
useEvent
is cached across all instances. This means that if if you recieve any event for a channel topic, and for example theuseEvent
hook unmounts, once it remounts, it will instantly load the last recieved data and state for the givenevent
.Previously if you recieved an event and the hook unmounted and remounted, the data stored in the
useEvent
hook was lost and you have needed to recieve the event again to get the data back.Once you leave a channel using
leave()
all cached data for theuseEvent
will be cleared.
-
useChannel
now accepts apassive
optionpassive
will instruct the channel to wait for another instance ofuseChannel
to connect with the necessary params and then once a connection is made, thepassive
channel will connect itself. See the js docs for more information.
2024-2-15
I have been using this version enough in a few complex projects and has been performing very well. I'd like to move away from alpha version and just iterate versions normally. I feel the API is pretty stable at this point and I am not anticipating much more deviation except for usePresence
. The usePresence
hook will need to be looked at in more depth to understand the most common access patterns and provide an API that applies to the most people. Currently it deviates quite a bit from the vanilla SDK in terms of the outputted data.
- Completely remove calling
useEvent
with astring
channel topic.- The benefit was reusing existing channels but
useChannel
now does it inherently by default. Additionally you usually want access to important channel metadata and functions likepush
andleave
which you simply did not get if you used a channelstring
. It is possible I reintroduce it in the future but it adds some more complexity and was not working consistently.
- The benefit was reusing existing channels but
-
Calling
useChannel
on the same channel topic across any number of components should just work, and keep all components connected and listening. Additionally, the state object should be consistent across alluseChannel
topics across components. -
expose an
isConnected
boolean insideusePhoenix
to know when the socket has officially connected. This is useful for example, in cases when you want to request data with push right when the socket connects, and you dont want to specify the socket itself as a dependency to the useEffect since it would trigger the useEffect many times.
2023-1-05
None
- Fix a bug where a component re-render would cause
useEvent
to stop listening and responding to the event correctly ifleave
was recently called.
2023-12-27
None
- Fix buggy behavior where the reference to
useChannel
functions would be changing on every render. This would cause your useEffects to run even if there should be no change.
2023-12-23
None
- Fixed a bug where if you successfully connected to a channel, but then later on the topic supplied to
useChannel
had changed tonull
and then back to the valid topic, theuseChannel
hook functions likepush
would no longer be holding a valid reference to the channel. Now, the hook will successfully update the reference and the functions will work as if the channel topic never changed. - Use the internel channel
ref
when usinguseChannel
'sleave
2023-12-17
- The typescript type for
useChannel
'sPushEvent
now aligns with the rest of the types
type PushEvent = {
- type: string;
+ event: string;
- payload?: Record<string, any>
+ data?: Record<string, any>
}
-
Added rollup build tooling which should reduce bundle size slightly
-
Phoenix.js is now marked as a peer dependency
-
useChannel
can now accept a short circuit operation to delay connecting to the channel until the condition is met.// Delay connecting until id is defined const [channel] = useChannel(id && `room:${id}`);
-
The
push
function type has been improved to catch more potential errors.