mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-26 09:14:22 +08:00
refactor: move more header stuff to elements package
This commit is contained in:
21
packages/native/src/getNamedContext.tsx
Normal file
21
packages/native/src/getNamedContext.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as React from 'react';
|
||||
|
||||
const contexts = new Map<string, React.Context<any>>();
|
||||
|
||||
export default function getNamedContext<T>(
|
||||
name: string,
|
||||
initialValue: T
|
||||
): React.Context<T> {
|
||||
let context = contexts.get(name);
|
||||
|
||||
if (context) {
|
||||
return context;
|
||||
}
|
||||
|
||||
context = React.createContext<T>(initialValue);
|
||||
context.displayName = name;
|
||||
|
||||
contexts.set(name, context);
|
||||
|
||||
return context;
|
||||
}
|
||||
@@ -17,4 +17,6 @@ export { default as useLinkBuilder } from './useLinkBuilder';
|
||||
|
||||
export { default as ServerContainer } from './ServerContainer';
|
||||
|
||||
export { default as getNamedContext } from './getNamedContext';
|
||||
|
||||
export * from './types';
|
||||
|
||||
Reference in New Issue
Block a user