How to use create-react-context - 10 common examples

To help you get started, we’ve selected a few create-react-context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andycall / RCRE / packages / rcre / src / core / context.ts View on Github external
export const RCREContext = createReactContext({
    $global: {},
    $location: URL.parse(''),
    lang: '',
    $query: {},
    debug: false,
    // lang: PropsTypes.string,
    events: new Events(),
    store: createReduxStore(),
    options: {},
    mode: 'React',
    containerGraph: new Map()
});

export const ComponentContext = createReactContext({
    model: '',
    $data: null,
    $tmp: null,
    dataCustomer: new DataCustomer(),
    setData: (name: string, value: any) => {},
    getData: (nameStr: string, props: any, isTmp?: boolean) => {},
    deleteData: (name: string, isTmp?: boolean) => {},
    setMultiData: (items: { name: string, value: any, isTmp: boolean }[]) => {}
});
github catamphetamine / react-responsive-ui / source / PageAndMenu.js View on Github external
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import createContext from 'create-react-context'

export const Context = createContext()

// export const contextPropTypes = {
// 	menuIsExpanded     : PropTypes.bool.isRequired,
// 	toggleMenu         : PropTypes.func.isRequired,
// 	registerMenu       : PropTypes.func.isRequired,
// 	registerMenuButton : PropTypes.func.isRequired,
// 	setTogglerCooldown : PropTypes.func.isRequired,
// 	getTogglerNode     : PropTypes.func.isRequired
// }

export default class PageAndMenu extends Component {
	constructor() {
		super()
		// `state` is placed here to so that it's initialized
		// after all instance methods because it references them.
		this.state = {
github glints-dev / glints-aries / stories / Provider.tsx View on Github external
uikitAssets[asset as keyof typeof uikitAssets],
      ])
    );
  }
  getUrl = (assetPath: string): string =>
    `${this.publicPath}${this.assetsMap.get(assetPath) || 'notfound'}`;
}

const DefaultLink = (
  props: React.DetailedHTMLProps<
    React.AnchorHTMLAttributes,
    HTMLAnchorElement
  >
) =&gt; <a>;

const UikitContext: Context = createContext(new Uikit('/', DefaultLink));
const UikitProvider = UikitContext.Provider;

interface Props {
  children: React.ReactElement;
}

const Provider: React.FunctionComponent = props =&gt; (
  
    {props.children}
  
);

export default Provider;
</a>
github skbkontur / retail-ui / packages / retail-ui / components / Tabs / TabsContext.ts View on Github external
import createReactContext from 'create-react-context';
import { Tab } from './Tab';
import { emptyHandler } from '../../lib/utils';

export interface TabsContextType {
  vertical: boolean;
  activeTab: string;
  getTab: (id: string) =&gt; Tab | null | void;
  addTab: (id: string, getNode: () =&gt; Tab) =&gt; void;
  notifyUpdate: () =&gt; void;
  removeTab: (id: string) =&gt; void;
  shiftFocus: (fromTab: string, delta: number) =&gt; void;
  switchTab: (id: string) =&gt; void;
}

export const TabsContext = createReactContext({
  vertical: false,
  activeTab: '',
  getTab: emptyHandler,
  addTab: emptyHandler,
  notifyUpdate: emptyHandler,
  removeTab: emptyHandler,
  shiftFocus: emptyHandler,
  switchTab: emptyHandler,
});
github react-navigation / react-navigation / src / views / NavigationContext.js View on Github external
import createReactContext from 'create-react-context';

const NavigationContext = createReactContext();

export const NavigationProvider = NavigationContext.Provider;
export const NavigationConsumer = NavigationContext.Consumer;

export default {
  NavigationProvider,
  NavigationConsumer,
};
github styletron / styletron / packages / styletron-react-core / src / index.js View on Github external
Ref,
  StatelessFunctionalComponent,
  ElementType,
  ElementConfig,
} from "react";
import React, {createElement, Component} from "react";

import createReactContext, {type Context} from "create-react-context";

import {addDebugMetadata, DebugEngine} from "./dev-tool.js";

export {DebugEngine};

const StyletronContext: Context = createReactContext();

const HydrationContext: Context = createReactContext(false);

const DebugEngineContext: Context = createReactContext();

class DevProvider extends Component {
  constructor(props: any) {
    super();
    this.state = {
      hydrating: Boolean(props.debugAfterHydration),
    };
  }

  componentDidMount() {
    if (__BROWSER__) {
      if (this.state.hydrating === true) {
        this.setState({hydrating: false});
      }
github yuanzhaohao / dashkit-ui / src / layout / context.tsx View on Github external
import * as React from 'react';
import createReactContext from 'create-react-context';

const LayoutContext = createReactContext(null);

export const LayoutProvider = LayoutContext.Provider;
export const LayoutConsumer = LayoutContext.Consumer;
export const createConsumer = (Component: any) =&gt; (props: any) =&gt; (
  
    {(context: any) =&gt; (
      
    )}
  
);
github gribnoysup / react-yandex-maps / src / Context.js View on Github external
throw new Error(message);
        }
        return ;
      }}
    
  );

  if (process.env.NODE_ENV !== 'production') {
    WithYMapsContext.displayName = `withYMapsContext(${displayName})`;
  }

  return WithYMapsContext;
};

export const ParentContext = createReactContext(null);

export const withParentContext = Component =&gt; {
  const WithParentContext = props =&gt; (
    
      {parent =&gt; }
    
  );

  if (process.env.NODE_ENV !== 'production') {
    WithParentContext.displayName = `withParentContext(${name(Component)})`;
  }

  return WithParentContext;
};
github jamesplease / react-state-context / src / index.js View on Github external
export default function createStateContext(actions = {}, initialState = null) {
  const Context = createReactContext();

  class ProviderComponent extends Component {
    render() {
      const { children } = this.props;

      const value = {
        ...this.actions,
        state: this.state,
      };

      return ;
    }

    constructor(...args) {
      super(...args);
github este / este / components / AppError.js View on Github external
import createReactContext, { type Context } from 'create-react-context';
import Text from './Text';
import { FormattedMessage } from 'react-intl';
import * as appError from '../lib/appError';

type Value = {|
  appError: ?appError.AppError,
  dispatchAppError: (appError: appError.AppError) =&gt; void,
|};

const value = {
  appError: null,
  dispatchAppError: () =&gt; {},
};

const AppErrorContext: Context = createReactContext(value);

export const AppErrorProvider = AppErrorContext.Provider;
export const AppErrorConsumer = AppErrorContext.Consumer;

class AppError extends React.PureComponent&lt;{}&gt; {
  static getAppErrorMessage = (appError: appError.AppError) =&gt; {
    switch (appError.name) {
      case 'failedToFetch':
        return (
          
        );
      case 'insufficientPermissions':
        return (

create-react-context

Polyfill for the proposed React context API

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Popular create-react-context functions