Client
`query`
`syncStatus`

syncStatus

Triplit's client storage is split into two areas - an outbox for unsynced updates and a cache for synced updates. Sometimes you may want to indicate that to a user that data has not yet been saved to the server. To do this, you can use the syncStatus method. This method accepts a single sync state (pending, confirmed, all) as an argument.

For example, a messaging app could use two queries to build message sent indicators. In React:

const allMessagesQuery = client.query('messages').order(['createdAt', 'ASC']);
 
const pendingMessagesQuery = client
  .query('messages')
  .select(['id'])
  .syncStatus('pending');
 
function Messages() {
  const { results: allMessages } = useQuery(client, allMessagesQuery);
  const { results: pendingMessages } = useQuery(client, pendingMessagesQuery);
 
  return (
    <div>
      {allMessages?.map((message) => (
        <div>
          <p>{message.text}</p>
          <p>
            {pendingMessages?.find(
              (pendingMessage) => pendingMessage.id === message.id
            )
              ? 'Sending...'
              : 'Sent'}
          </p>
        </div>
      ))}
    </div>
  );
}