MethodsStatic Display Method | Fire Snippets Docs
Static Display Method
Displays static data from Firestore with optional real-time updates.
staticDisplay(snippetId, variables, onUpdate)
Description
Displays data from Firestore in specified HTML elements, updating the content in real-time if enabled. It can handle both document and collection references, apply query conditions, and sort orders.
Method Signature
staticDisplay(snippetId, variables, onUpdate)
Parameters
- snippetId: (string) The ID of the static display snippet configuration.
- variables: (Array) An array of objects containing variable names and values to replace placeholders in the Firestore path or query conditions.
- onUpdate: (function) A callback function that is called whenever data is fetched or updated. Receives the data as a parameter.
Returns
- Promise: Resolves with an object containing an
unsubscribe
method to stop real-time updates, or rejects with an error.
Usage Example
// Initialize FireSnippets
const fireSnippets = new FireSnippets('your-api-key');
// Define variables for placeholders
const variables = [
{ name: 'userId', value: '12345' }
];
// Define the onUpdate callback
const onUpdate = (data) => {
// Data updated
console.log('Data updated:', data);
};
// Call the staticDisplay method
fireSnippets.staticDisplay('your-static-snippet-id', variables, onUpdate)
.then(result => {
// Initial data fetched and displayed
console.log('Static display initialized.');
// To stop real-time updates
// result.unsubscribe();
})
.catch(error => {
// Handle errors
console.error('Error displaying data:', error);
});
HTML Elements Required
Ensure your HTML includes the elements with IDs specified in your fieldMappings
:
<div id="title-element"></div>
<div id="content-element"></div>
Was this helpful?