We're deprecating local state initializers #198
nvie
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We're in the process of refactoring some internals to be the foundation of a slew of new future Liveblocks features. In the short term, our focus is on improving:
Slightly longer term, these changes will pave the way for new features like:
Starting with 0.16.4, we're deprecating the use of the second argument to the
useList()
,useObject()
anduseMap()
hooks. In the next major version, 0.17, we're going to throw errors when this argument is used. Then, in 0.18, we're going to be removing that API entirely.Doing so will unblock progress on the longer-term goals mentioned above.
New recommended way to initialize state
In particular, we're recommending a new state initialization pattern, where in our React API, you centrally initialize your Presence and Storage as soon as you enter the room.
We're no longer recommending this pattern:
Instead, initialize your Storage by declaring it at the RoomProvider level, aka when you enter the Room:
Your components then just "read" the data, like so:
This has the benefit of keeping your app's state visible and manageable from a single place, rather than scattered throughout your app. Another benefit is that it avoids potential conflicts where two components use the same storage key, but disagree over the default value.
Adopting this pattern has many other benefits. It will enable us to provide better TypeScript types, and provide future APIs for schema validation, data migration, structural sharing, and improvements to our subscription model.
Changes to
@liveblocks/react
We've renamed the following props on
RoomProvider
:defaultPresence
->initialPresence
defaultStorageRoot
->initialStorage
Changes to
@liveblocks/client
We've renamed the following options to
client.enter()
:defaultPresence
->initialPresence
defaultStorageRoot
->initialStorage
We're here to help! 😇
If you need any assistence with making this change, we're here to help! Hit us up on Discord, or open an issue, and we'll make sure to help you out! 🙏
Beta Was this translation helpful? Give feedback.
All reactions