Component SDK → PrivateData API

The PrivateData API is a Component SDK API that enables developers to store any data that is not derived from configurations, settings, or measures. You can use this API to store any data that is considered user’s preference while rendering the developed component, such as element order and position.

Syntax

const { privateData, setPrivateData } = usePrivateData();
// set function to save any primitive value related to the insight
setPrivateData(anyvalue)
// get variable to retrieve back the saved value
console.log(privateData)

Input Attributes

This API sets primitive data only, such as integers and json.

Returns

Primitive data sent in the input attribute.

Examples

The following is an example of how to use the API. In this example, the API is used to set a primitive value upon selecting the Save button.

import {
AppliedPrompts,
Context,
onDrillDownFunction,
ResponseData,
TContext,
usePrivateData
} from '@incorta-org/component-sdk';
import React, { useRef } from 'react';
interface Props {
context: Context<TContext>;
prompts: AppliedPrompts;
data: ResponseData;
drillDown: onDrillDownFunction;
}
const Pkg = ({ context, prompts, data, drillDown }: Props) => {
const ref = useRef<HTMLInputElement>(null);
const { privateData, setPrivateData } = usePrivateData();
return (
<div className="test">
<h1>Hello Incorta Component</h1>
<input defaultValue={privateData} ref={ref} />
<button onClick={() => setPrivateData(ref.current?.value)}>Save</button>
<br />
{privateData}
</div>
);
};