Available React Hooks#
This page describes the React hooks available for use.
.. note:: The following React hooks are available under the Hooks
object for use, e.g. Hooks.useCollection
.
useCollection#
useCollection(collection, isEmpty, serializer, additionalDeps)
This hook attaches a Backbone collection to a React state and returns a serialized collection object together with loading and isError
collection states.
Arguments:
Collection - Backbone collection object
isEmpty - Custom function that will determine if the collection is empty. Most of the time you can just check if
collection.length === 0
, but sometimes you may need to do additional things depending on the use case.Serializer - Optional serializer function. If it’s not passed collection will be serialized with
collection.toJSON()
additionalDeps - Additional
useEffect
dependencies that will trigger collection refetch on change. By default, the only dependency is the dashboard state object, but you can pass additional ones if needed.
useCollectionRecreate#
useCollectionRecreate = (getCollection, props, config)
This hook recreates a collection based on a change in the parameters.
Arguments:
GetCollection: Function to get a collection with parameters.
WidgetProps: An object representing widget properties to be passed down.
Config: An object representing widget config to be passed down.
useWidgetCollection#
useWidgetCollection(widgetProps, collection, isEmpty, serializer, additionalDeps)
This hook attaches a Backbone collection to a React state and returns an object with all properties needed for a widget. You can use this hook when setting up the main collection for the widget.
It uses the useCollection
hook but also adds additional data and structure that helps with passing properties to widget containers and the widgets themselves.
Arguments:
widgetProps - An object representing widget properties to be passed down.
Collection: Backbone collection object
isEmpty: Custom function determining if the collection is empty. Mostly, you can check if
collection.length === 0
, though sometimes additional configuration is needed depending on the use case.Serializer: Optional serializer function. If not passed, then collection will be serialized with
collection.toJSON()
additionalDeps: Additional
useEffect
dependencies that trigger collection refetch on change. By default, the only dependency is the dashboard state object, though you can pass additional ones if needed.
useCommunityTypesCollection#
useCommunityTypesCollection = (props, collection, isEmpty, dashboardSection, serializer)
This hook calls the useWidgetCollection
hook and provides a list of additional methods and parameters specific to CommunityTypesCollection
.
Additional return parameters:
GetModelById: Function to get a CommunityType by ID.
Total: Number of Community Types.
Arguments:
WidgetProps: An object representing widget properties to be passed down.
Collection: Backbone collection object.
isEmpty: Custom function determining if the collection is empty. Mostly, you can check if
collection.length === 0
, though sometimes additional configuration is needed depending on the use case.DashboardSection: The widget section in the Dashboard.
Serializer: Optional serializer function. If not passed, then collection will be serialized with
collection.toJSON()
.
useCommunityCollection#
useCommunityCollection = (props, collection, isEmpty, dashboardSection, serializer, additionalDeps)
This hook calls the useWidgetCollection
hook and provides a list of additional methods and parameters specific to CommunityCollection
.
Additional return parameters:
GetModelById: Function to get a Community by ID.
Total: Number of Communities.
LoadNextPage: Function to load the Collection next page (pagination).
Arguments:
WidgetProps: An object representing widget properties to be passed down.
Collection: Backbone collection object
isEmpty: Custom function determining if the collection is empty. Mostly, you can check if
collection.length === 0
, though sometimes additional configuration is needed depending on the use case.DashboardSection: The widget section in the Dashboard.
Serializer: Optional serializer function. If not passed, then collection will be serialized with
collection.toJSON()
.AdditionalDeps: Additional
useEffect
dependencies that trigger collection refetch on change. By default, the only dependency is the dashboard state object, though you can pass additional ones if needed.
useCommunitySubscriptionsCollection#
useCommunitySubscriptionsCollection = (props, collection, isEmpty, dashboardSection, serializer)
This hook calls the useWidgetCollection
hook and provides a list of additional methods and parameters specific to CommunitySubscriptionsCollection
.
Additional return parameters:
GetModelById: Function to get a CommunitySubscription by ID.
Total: Number of CommunitySubscriptions.
LoadNextPage: Function to load the Collection next page (pagination).
Create: Function to create a new CommunitySubscription.
RefetchCollection: Function to refetch the Collection.
BulkCreate: Function to create multiple CommunitySubscriptions.
Arguments:
WidgetProps - An object representing widget properties to be passed down.
Collection - Backbone collection object
isEmpty - Custom function determining if the collection is empty. Mostly, you can check if collection.length === 0, though sometimes additional configuration is needed depending on the use case.
DashboardSection - The widget section in the Dashboard
Serializer - Optional serializer function. If not passed, then collection will be serialized with collection.toJSON()
useContainerDimensions#
useContainerDimensions(ref)
This hook will return the width and the height of an HTML element.
Dimensions are updated on load, on mount/un-mount, when resizing the window, and when the ref changes.
Argument:
Ref: React ref object representing html element. For more information, see the Refs and the DOM reference page.
Example:
const elementRef = React.useRef(null);
const { containerWidth, containerHeight } = useContainerDimensions(carouselRef);
return <SomeComponent ref={elementRef}>
useDrilldown#
useDrilldown(search, widgetModel)
This hook drills down the dashboards by adding queries and facets to dashboard state and widget selection. When called, it will return the four drill-down functions documented below.
Arguments:
search: Dashboard state object available in the widget props or
Global
variable.widgetModel: Widget configuration model available in the props and context of the widget.
Example:
const { addFacetValue, removeFacetValue, clearSelection, removeQueryFromSelection, } = useDrilldown(dashboardState, widgetModel);
Functions#
The following functions are returned by useDrilldown:
addFacetValue#
addFacetValue(facet, value)
This hook adds a facet or query to the dashboard state and widget selection. If only a value is provided, it will add that value as a query. If both are provided, it will add a facet-value pair.
Arguments:
Facet: A string representing a facet.
Value: A string representing a facet value, or query if the facet is empty.
Example:
const { addFacetValue } = useDrilldown(props.dashboardState, props.widgetModel);
addFacetValue('source', props.sources[0]?.id);
removeFacetValue#
removeFacetValue(facet, value, silent)
This hook removes a facet or query from the dashboard state and widget selection. If only a value is provided, it will remove that value as a query. If both are provided, it will remove the identified facet-value pair.
Arguments:
Facet: A string representing a facet.
Value: A string representing a facet value, or query if the facet is empty.
Silent: If true, the function call will not trigger any events.
removeFacetValue#
clearSelection()
will remove the full selection for the current widget model from both the dashboard and widget selections. There are no arguments.
removeQueryFromSelection#
removeQueryFromSelection(silent)
This hook will remove the first selection for the current widget model from both the dashboard and widget selections.
Argument:
Silent: if true, the function call will not trigger any events.
useFacetsCollection#
useFacetsCollection = (props, collection, isEmpty, dashboardSection, serializer)
This hook calls the useWidgetCollection
hook and provides a list of additional methods and parameters specific to FacetsCollection
.
Additional return parameters:
GetModelById: Function to get a Facet by ID.
Indexed: List of Indexed Facets.
Arguments:
WidgetProps: An object representing widget properties to be passed down.
Collection: Backbone collection object.
isEmpty: Custom function determining if the collection is empty. Mostly, you can check if
collection.length === 0
, though sometimes additional configuration is needed depending on the use case.DashboardSection: The widget section in the Dashboard.
Serializer: Optional serializer function. If not passed, then collection will be serialized with
collection.toJSON()
.
useFeedbackMode#
useFeedbackMode = (dashboard)
This hook tracks the FeedbackMode
in a dashboard and returns the boolean
representing the current mode and a setFeedbackMode
function to change it.
Argument:
Dashboard: Dashboard model, available in all the widgets props.
useItemsCollection#
useItemsCollection = (props, collection, overrides, apiOverrides, dashboardSection,additionalDeps, isEmpty, serializer)
This hook calls the useWidgetCollection
hook, attaches additional events, and provides a list of additional methods and parameters specific to ItemsCollection
.
Additional return parameters:
LoadNextPage: Function to load the Collection next page (pagination).
ActiveItem: The current active Item.
SetActiveItem: Function to set the active Item.
GetActiveItem: Function to get the active Item.
ActiveEntity: The current active Entity.
SetActiveEntity: Function to set the active Entity.
GetActiveEntity: Function to get the active Entity.
GetExcelUrl: Function to get the Excel URL.
GetModelById: Function to get an Item by ID.
OnEntityClick: Function to be called when an Entity is clicked.
Arguments:
WidgetProps: An object representing widget properties to be passed down.
Collection: Backbone collection object.
Overrides: Object containing all the Widget Component Overrides.
ApiOverrides: Object containing all the Widget API Overrides.
DashboardSection: The widget section in the Dashboard.
isEmpty: Custom function determining if the collection is empty. Mostly, you can check if
collection.length === 0
, though sometimes additional configuration is needed depending on the use case.Serializer: Optional serializer function. If not passed, then collection will be serialized with
collection.toJSON()
.AdditionalDeps - Additional
useEffect
dependencies that trigger collection refetch on change. By default, the only dependency is the dashboard state object, though you can pass additional ones if needed.
useQueryEvaluator#
useQueryEvaluator = (additionalQuery, dashboard, user, search)
This hook evaluates the query and attaches events to the Dashboard Store and returns it as a string.
Arguments: 1. AdditionalQuery: Additional widget query as a string. 2. Dashboard: Dashboard model available in all the widget props. 3. User: User model. 4. Search: Search model, available in all the widget props.
useStoreKeyChange#
useStoreKeyChange = (dashboard, storeKey, event)
This hook tracks a store key based on a given event and returns the value.
Arguments:
Dashboard: Dashboard model, available in all the widgets props.
StoreKey: A string representing the store key.
Event: A string representing the event.
useStateWithCallback#
useStateWithCallback = (initialValue)
This hook saves a state value and returns the current value and a function to update the value and use a specified callback function.
Argument:
InitialValue: The initial value of the state, can be of any
type.
Example:
const [value, setValueAndCallback] = useStateWithCallback('firstValue');
setValueAndCallback('secondValue', (prevValue, newValue) => console.log(`Previous value: ${prevValue}, New value: ${newValue}`));
useWithoutCollection#
useWithoutCollection = (widgetProps)
This hook acts similarly to useCollection
but it doesn’t use a collection. It can be used for widgets without specified collections.
Argument:
WidgetProps: An object representing widget properties to be passed down.
usePrevious#
usePrevious = (value)
This hook tracks the previous value of a given one and returns it.
Argument:
Value: Mutating value of any kind.