Kvaser CanKing GUI Extensions SDK v7.4.0
Kvaser CanKing GUI Extensions SDK / hooks / useSessionData
Function: useSessionData()
useSessionData<
T>(id,defaultValue,loadedCallback?):object
A hook for data that should be saved to the session data. The state is automatically saved to and restored from the main process.
Type Parameters
T
T
The type of the session data. Must be JSON serializable.
Parameters
id
number
The unique id of the view. This is passed to the view component as the id prop.
defaultValue
The default value or a function that returns the default value.
T | () => T
loadedCallback?
(value) => void
Optional callback invoked once after data is loaded.
Returns
object
An object with a flag indicating if the session data has been initialized, the current session data and a setter callback.
sessionData
sessionData:
T
sessionDataIsInitialized
sessionDataIsInitialized:
boolean
setSessionData
setSessionData:
Dispatch<SetStateAction<T>>
Remarks
It’s only possible to use this hook once per workspace view component tree.
Use this hook if your view component only needs to store a small amount of session data.
For larger amounts of data, consider using useSessionDataSlice instead, which allows
splitting the session data into multiple named slices.
Using multiple slices can improve performance and reduce memory usage and it also allows
different parts of the component tree to independently load and save their session data.