當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript react.createContext函數代碼示例

本文整理匯總了TypeScript中react.createContext函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createContext函數的具體用法?TypeScript createContext怎麽用?TypeScript createContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createContext函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

import * as React from 'react'
import { ChartConfig } from 'charts/ChartConfig'
import { ChartView } from 'charts/ChartView'
import { VNode } from 'charts/Util'

export interface ChartViewContextType {
    chart: ChartConfig
    chartView: ChartView
    baseFontSize: number
    isStatic: boolean
    addPopup: (vnode: VNode) => void,
    removePopup: (vnode: VNode) => void
}

const ChartViewContext: React.Context<ChartViewContextType> = React.createContext({}) as any
export { ChartViewContext }
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:16,代碼來源:ChartViewContext.ts

示例2: createContext

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { createContext } from 'react';

interface UMRefreshContext {
  lastRefresh: number;
}

const defaultContext: UMRefreshContext = {
  lastRefresh: 0,
};

export const UptimeRefreshContext = createContext(defaultContext);
開發者ID:,項目名稱:,代碼行數:17,代碼來源:

示例3: isKibanaContext

import { IndexPattern } from 'ui/index_patterns';

export interface KibanaContextValue {
  combinedQuery: any;
  currentIndexPattern: IndexPattern;
  currentSavedSearch: any;
  indexPatterns: any;
  kbnBaseUrl: string;
  kibanaConfig: any;
}

export type SavedSearchQuery = object;

// Because we're only getting the actual contextvalue within a wrapping angular component,
// we need to initialize here with `null` because TypeScript doesn't allow createContext()
// without a default value. The nullable union type takes care of allowing
// the actual required type and `null`.
export type NullableKibanaContextValue = KibanaContextValue | null;
export const KibanaContext = React.createContext<NullableKibanaContextValue>(null);

export function isKibanaContext(arg: any): arg is KibanaContextValue {
  return (
    arg.combinedQuery !== undefined &&
    arg.currentIndexPattern !== undefined &&
    arg.currentSavedSearch !== undefined &&
    arg.indexPatterns !== undefined &&
    typeof arg.kbnBaseUrl === 'string' &&
    arg.kibanaConfig !== undefined
  );
}
開發者ID:elastic,項目名稱:kibana,代碼行數:30,代碼來源:kibana_context.ts

示例4: requestUIKeydown

export const defaultFullScreenState: FullScreenNavState = {
  initial: true,
  visibleComponentLeft: '',
  visibleComponentRight: '',
  inventoryItems: null,
  equippedItems: null,
  containerIdToDrawerInfo: {},
  stackGroupIdToItemIDs: {},
  myTradeItems: null,
  myTradeState: SecureTradeState.None,
  tabsLeft: defaultTabsLeft,
  tabsRight: defaultTabsRight,
  invBodyDimensions: { width: 0, height: 0 },
};

export const FullScreenContext = React.createContext(defaultFullScreenState);

export function requestUIKeydown() {
  const shouldFullscreenListen = false;
  events.fire('hudfullscreen-shouldListenKeydown', shouldFullscreenListen);
}

export function releaseUIKeydown() {
  const shouldFullscreenListen = true;
  events.fire('hudfullscreen-shouldListenKeydown', shouldFullscreenListen);
}

export function isRightOrLeftItem(gearSlots: GearSlotDefRef.Fragment[]) {
  if (gearSlots.length === 1) {
    const firstGearSlotId = gearSlots[0].id;
    return _.includes(firstGearSlotId.toLowerCase(), 'right') ||
開發者ID:codecorsair,項目名稱:Camelot-Unchained,代碼行數:31,代碼來源:utils.ts

示例5:

  refetch: () => {},
  statusCode: 0,
};

export const defaultContextState: HUDContextState = {
  skills: {
    ...defaultQueryResultInfo,
    data: [],
  },
  itemDefRefs: {
    ...defaultQueryResultInfo,
    data: [],
  },
};

export const HUDContext = React.createContext(defaultContextState);

export const skillsQuery = `
  {
    myCharacter {
      skills {
        id
        name
        icon
        notes
        tracks
      }
    }
  }
`;
開發者ID:csegames,項目名稱:Camelot-Unchained,代碼行數:30,代碼來源:context.ts

示例6: updateCurrentDocument

  updateCurrentDocument(sender?: Partial<PubDocument>): void;
  adjustObjectLayer(sender: LayerMutationDelta): void;
  setStartModalVisible(visible: boolean): void;
  setNewAccountModalVisible(visible: boolean): void;
  setLoginModalVisible(visible: boolean): void;
  setAboutModalVisible(visible: boolean): void;
  setCurrentDocument: React.Dispatch<PubDocument | null>;
}

export interface PubAppState {
  actions: PubActions;
  currentDocument: PubDocument | null;
  clipboardContents: PubShape | null;
  dataLoaded: boolean;
  documents: Array<PubDocument>;
  layersPanelVisible: boolean;
  selectedObject: PubShape | null;
  user: PubUser | null;
  zoom: number;
  startModalVisible: boolean;
  loginModalVisible: boolean;
  newAccountModalVisible: boolean;
  openDocumentModalVisible: boolean;
  aboutModalVisible: boolean;
  newDocumentModalVisible: boolean;
}

export const StateContext = React.createContext<PubAppState>(
  null as PubAppState
);
開發者ID:carlospaelinck,項目名稱:publications-js,代碼行數:30,代碼來源:app-state.ts

示例7: createContext

import { createContext } from "react";

export interface IMessage {
  text: string;
  onUndo?: () => void;
}
export const MessageContext = createContext(undefined);

export * from "./MessageManager";
export default MessageContext.Consumer;
開發者ID:elwoodxblues,項目名稱:saleor,代碼行數:10,代碼來源:index.ts

示例8:

import * as React from 'react'
import { Admin } from './Admin'

const AdminAppContext: React.Context<{ admin: Admin }> = React.createContext({}) as any
export { AdminAppContext }
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:5,代碼來源:AdminAppContext.ts

示例9: useContext

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { ApolloClient } from 'apollo-client';
import { createContext, useContext } from 'react';

/**
 * This is a temporary provider and hook for use with hooks until react-apollo
 * has upgraded to the new-style `createContext` api.
 */

export const ApolloClientContext = createContext<ApolloClient<{}> | undefined>(undefined);

export const useApolloClient = () => {
  return useContext(ApolloClientContext);
};
開發者ID:elastic,項目名稱:kibana,代碼行數:19,代碼來源:apollo_context.ts

示例10:

import Kefir, { Pool } from 'kefir';
import { Action } from 'redux';
import { createContext } from 'react';

const { Provider, Consumer } = createContext<Pool<Action, Error>>(Kefir.pool());

export { Provider, Consumer };
開發者ID:valtech-nyc,項目名稱:brookjs,代碼行數:7,代碼來源:context.ts


注:本文中的react.createContext函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。