This is a JavaScript utility designed to simplify the interaction and manipulation of data layers. It's particularly useful for managing and tracking data in complex applications, enhancing data handling capabilities with ease.
Install the package via npm:
npm install @frankhoodbs/data-layer-helper
or using yarn:
yarn add @frankhoodbs/data-layer-helper
First, import the useDataLayer
function from the package:
import { useDataLayer } from '@frankhoodbs/data-layer-helper';
Then, you can initialize it with a set of layers and optionally a store object. Using TypeScript generics here provides the benefit of autocompletion in your IDE:
const { push } = useDataLayer<['layer1', 'layer2']>(['layer1', 'layer2']);
You can push data into your layers as follows:
push(
{ key: 'value' },
{
layer1: { additionalKey: 'additionalValue' },
layer2: { key: 'overrideValue' },
}
);
- data: The data object to be pushed to every layer.
- overrides: (Optional) An object containing layer-specific overrides.
-
debug: (Optional) If set to
true
, the data will be logged to the console instead of being pushed to the layers.
- Easy setup for managing multiple data layers.
- Layer-specific data overrides.
- Debug mode for development and testing.