mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
* Add copyright script Copied over our copyright script from the react repo. I made a small fix to handle shebangs. * Update copyright on all files Run the script.
31 lines
1021 B
TypeScript
31 lines
1021 B
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
// Error Decoder requires reading pregenerated error message from getStaticProps,
|
|
// but MDX component doesn't support props. So we use React Context to populate
|
|
// the value without prop-drilling.
|
|
// TODO: Replace with React.cache + React.use when migrating to Next.js App Router
|
|
|
|
import {createContext, useContext} from 'react';
|
|
|
|
const notInErrorDecoderContext = Symbol('not in error decoder context');
|
|
|
|
export const ErrorDecoderContext = createContext<
|
|
| {errorMessage: string | null; errorCode: string | null}
|
|
| typeof notInErrorDecoderContext
|
|
>(notInErrorDecoderContext);
|
|
|
|
export const useErrorDecoderParams = () => {
|
|
const params = useContext(ErrorDecoderContext);
|
|
|
|
if (params === notInErrorDecoderContext) {
|
|
throw new Error('useErrorDecoder must be used in error decoder pages only');
|
|
}
|
|
|
|
return params;
|
|
};
|