DataInstanceStore
DataInstanceStore
is used to work with a single instance of some Entity. It can be created via instance initializer function:
dataInstance = instance<Pet>(Pet.NAME, {view: 'pet-with-owner-and-type', loadImmediately: false});
In a functional component you’ll need to wrap the call to instance
in React.useRef or use a convenience hook useInstance.
const dataInstance = useInstance<Pet>(
Pet.NAME,
{
view: 'pet-with-owner-and-type',
loadImmediately: false
}
);
// Note that `dataInstance` in this case is a React's `MutableRefObject`.
// The `DataInstanceStore` is contained in its `current` property.
dataInstance.current.load(entityId);
Use dataInstance.commit()
method to perform entity update:
dataInstance.item.name = 'New Name';
dataInstance.commit()
For String ID entities you’ll need to provide the name of the String ID attribute as a stringIdName
parameter.
dataInstance = instance<Pet>(Pet.NAME, {
stringIdName: 'identifier'
});
API: DataInstanceStore, instance, useInstance.