objectUtils
Reference
Utility functions for inspecting plain JavaScript objects.
const { protrakUtils } = React.useContext(customWidgetContext);
const { isEmpty, isArrayOfObject } = protrakUtils;
isEmpty(obj)
Returns true if the object has no own enumerable properties. Returns false for File objects (even if they appear empty).
Parameters:
| Param | Type | Description |
|---|---|---|
obj | object | The object to test |
Returns: boolean
isEmpty({}); // → true
isEmpty({ name: 'Agreement' }); // → false
isEmpty(new File([], 'test.txt')); // → false (File objects are always non-empty)
isArrayOfObject(arr)
Returns true if the array contains at least one element that is of type object.
Parameters:
| Param | Type | Description |
|---|---|---|
arr | Array | The array to inspect |
Returns: boolean
isArrayOfObject([1, 2, 3]); // → false
isArrayOfObject(['a', 'b']); // → false
isArrayOfObject([{ id: 1 }, { id: 2 }]); // → true
isArrayOfObject([1, { id: 2 }]); // → true
Usage Example
function AttributeSummaryWidget(pageContext) {
const { protrakUtils, protrakComponents } =
React.useContext(customWidgetContext);
const { isEmpty } = protrakUtils;
const { Box, Text } = protrakComponents;
const { attributeValues } = pageContext;
if (isEmpty(attributeValues)) {
return <Text>No attributes available.</Text>;
}
return (
<Box>
{Object.entries(attributeValues).map(([key, attr]) => (
<Text key={key}>
{key}: {attr.textValue ?? attr.numericValue ?? '—'}
</Text>
))}
</Box>
);
}