Used to get the request context in the BFF function.


according to the framework extend plugin, export from the corresponding namespace:

import { useContext } from '@modern-js/runtime/{namespace}';

Function Signature

function useContext(): any


Developers can get more request information through context, such as browser UA(an example is when using the koa framework):

import { useContext } from '@modern-js/runtime/koa';

export async function get() {
  const ctx = useContext();
  return ctx.req.headers['user-agent'];

only in BFF function, useContext API can be used.

Although the useContext API is supported in any framework extend plugin, the types of return values are different.