EntityProvider is the standard way to load and work with a single entity. Wrap a component tree with it, then use useEntity in any descendant to access the entity’s data and actions.
Setting Up EntityProvider
EntityProvider accepts one of four mutually exclusive identifier props:
By foreign ID
Use this when your entity is linked to an item in your own system. Pass
createIfNotFound to auto-create the entity if it doesn’t exist yet.EntityProvider renders null if none of the identifier props are provided. Exactly one must be present.Accessing Entity State with useEntity
Inside any child of EntityProvider, call useEntity() to access the entity and its actions:
useEntity Return Values
The loaded entity.
undefined while loading, null if not found.Direct state setter. Use this if you need to manually update the local entity state.
Updates the entity and syncs the new state locally. Accepts:
title— new titlecontent— new contentattachments— array of attachment objectskeywords— array of keyword stringslocation—{ latitude, longitude }metadata— arbitrary JSON objectmentions— array ofMentionobjects
Deletes the entity and sets local state to
undefined.EntityProvider Props Reference
Replyke entity ID. Mutually exclusive with
foreignId, shortId, and entity.Your system’s ID for this entity. Mutually exclusive with the others.
Auto-generated short identifier. Mutually exclusive with the others.
A pre-fetched entity object. Pass this to avoid a redundant fetch. Mutually exclusive with the others.
Only valid with
foreignId. If true, the entity is automatically created when it doesn’t exist yet. Useful for “entity-per-resource” patterns.
