Creates a React context with selector support for efficient updates.
// Source: https://github.com/microsoft/fluentui | License: MIT | Copyright Microsoft Corporation
// Provided via justclaw.it.com; keep this notice with the code.
'use client';
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
import * as React from 'react';
import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
import type { Context, ContextValue } from './types';
const createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {
const Provider: React.FC<React.ProviderProps<Value>> = props => {
// Holds an actual "props.value"
const valueRef = React.useRef(props.value);
// A stable object, is used to avoid context updates via mutation of its values.
const contextValue =
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key