Skip to main content

useMMAppContext

A hook for consuming widget settings configured through useMMAppSetting. This hook provides access to the current values of widget settings.

Usage​

import React from 'react';
import { Box, Text } from '@chakra-ui/react';
import { useMMAppContext } from '@machinemetrics/mm-react-tools';

function MyWidget() {
const { threshold, metric } = useMMAppContext();

return (
<Box>
<Text>Current threshold: {threshold}</Text>
<Text>Selected metric: {metric}</Text>
</Box>
);
}

Properties​

The hook returns an object containing all the settings defined using useMMAppSetting. Each property corresponds to the key used in the useMMAppSetting hook.

For example, if you defined settings like this:

useMMAppSetting("threshold", { ... });
useMMAppSetting("metric", { ... });

Then useMMAppContext will return:

{
threshold: "value",
metric: "selected-metric"
}