Merge pull request #224 from antvis/fix/react-scene

fix: 修复MapboxScene的容器找不到
This commit is contained in:
Claire_Yecao 2020-02-22 22:23:36 +08:00 committed by GitHub
commit 547ebf4403
4 changed files with 8 additions and 7 deletions

View File

@ -33,7 +33,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene.setMapStyle(map.style); scene.setMapStyle(map.style);
}, [map.style]); }, [map.style]);
return scene !== undefined ? ( return (
<SceneContext.Provider value={scene}> <SceneContext.Provider value={scene}>
{createElement( {createElement(
'div', 'div',
@ -45,7 +45,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene && props.children, scene && props.children,
)} )}
</SceneContext.Provider> </SceneContext.Provider>
) : null; );
}); });
export default AMapScene; export default AMapScene;

View File

@ -58,7 +58,7 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
} }
}, [map.rotation]); }, [map.rotation]);
return scene !== undefined ? ( return (
<SceneContext.Provider value={scene}> <SceneContext.Provider value={scene}>
{createElement( {createElement(
'div', 'div',
@ -70,7 +70,7 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
scene && props.children, scene && props.children,
)} )}
</SceneContext.Provider> </SceneContext.Provider>
) : null; );
}); });
export default MapboxScene; export default MapboxScene;

View File

@ -25,7 +25,7 @@ export default React.memo((props: IMapSceneConig) => {
}; };
}, []); }, []);
return scene !== null && scene !== undefined ? ( return (
<SceneContext.Provider value={scene}> <SceneContext.Provider value={scene}>
{createElement( {createElement(
'div', 'div',
@ -37,5 +37,5 @@ export default React.memo((props: IMapSceneConig) => {
scene && props.children, scene && props.children,
)} )}
</SceneContext.Provider> </SceneContext.Provider>
) : null; );
}); });

View File

@ -1,7 +1,8 @@
import { Scene } from '@antv/l7'; import { Scene } from '@antv/l7';
import { createContext, useContext } from 'react'; import { createContext, useContext } from 'react';
export const SceneContext = createContext({}); // tslint:disable-next-line: no-object-literal-type-assertion
export const SceneContext = createContext<Scene | undefined>({} as Scene);
export function useSceneValue(): Scene { export function useSceneValue(): Scene {
return (useContext(SceneContext) as unknown) as Scene; return (useContext(SceneContext) as unknown) as Scene;
} }