useUXPContext

A custom React hook that retrieves the UXPContext, throwing an error if used outside a UXPContextProvider.

Installation

import { useUXPContext } from 'uxp/components';

Signature

function useUXPContext(): IContextProvider

Examples

import { UXPContext } from './Context';
import { useUXPContext } from './useUXPContext';

const MyComponent = () => {
  const context = useUXPContext();
  return <div>{context.$L('hello')}</div>;
};
import { UXPContext } from './Context';
import { useUXPContext } from './useUXPContext';

const MyComponent = () => {
  const { $L, direction } = useUXPContext();
  return (
    <div style={{ direction: direction }}>
      <p>{ $L('welcome_message') }</p>
    </div>
  );
};

Last updated