From bf73643b13fe65baf006ebdc6d2b421c0835d95d Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 13 Apr 2018 09:49:06 +0800 Subject: [PATCH] change to new context api --- package.json | 4 ++-- src/components/PageHeader/index.js | 15 ++++----------- src/layouts/BasicLayout.js | 18 ++++++++---------- src/layouts/MeunContext.js | 3 +++ src/layouts/PageHeaderLayout.js | 7 ++++++- 5 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 src/layouts/MeunContext.js diff --git a/package.json b/package.json index f2f8eebd..0e4d4224 100755 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "dependencies": { "@antv/data-set": "^0.8.0", "@babel/polyfill": "^7.0.0-beta.36", - "@types/react": "^16.3.5", - "@types/react-dom": "^16.0.4", + "@types/react": "^16.3.8", + "@types/react-dom": "^16.0.5", "antd": "^3.4.0", "babel-runtime": "^6.9.2", "bizcharts": "^3.1.3-beta.1", diff --git a/src/components/PageHeader/index.js b/src/components/PageHeader/index.js index a36fa7f1..f4dab5c1 100644 --- a/src/components/PageHeader/index.js +++ b/src/components/PageHeader/index.js @@ -1,5 +1,4 @@ import React, { PureComponent, createElement } from 'react'; -import PropTypes from 'prop-types'; import pathToRegexp from 'path-to-regexp'; import { Breadcrumb, Tabs } from 'antd'; import classNames from 'classnames'; @@ -20,12 +19,6 @@ export function getBreadcrumb(breadcrumbNameMap, url) { } export default class PageHeader extends PureComponent { - static contextTypes = { - routes: PropTypes.array, - params: PropTypes.object, - location: PropTypes.object, - breadcrumbNameMap: PropTypes.object, - }; onChange = key => { if (this.props.onTabChange) { this.props.onTabChange(key); @@ -33,10 +26,10 @@ export default class PageHeader extends PureComponent { }; getBreadcrumbProps = () => { return { - routes: this.props.routes || this.context.routes, - params: this.props.params || this.context.params, - routerLocation: this.props.location || this.context.location, - breadcrumbNameMap: this.props.breadcrumbNameMap || this.context.breadcrumbNameMap, + routes: this.props.routes, + params: this.props.params, + routerLocation: this.props.location, + breadcrumbNameMap: this.props.breadcrumbNameMap, }; }; // Generated according to props diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 3e472658..26d7f9e2 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -1,5 +1,4 @@ import React from 'react'; -import PropTypes from 'prop-types'; import { Layout } from 'antd'; import DocumentTitle from 'react-document-title'; import { connect } from 'dva'; @@ -14,6 +13,7 @@ import Sidebar from '../components/Sidebar'; import logo from '../assets/logo.svg'; import Footer from './Footer'; import Header from './Header'; +import Context from './MeunContext'; const { Content } = Layout; const { AuthorizedRoute, check } = Authorized; @@ -61,11 +61,7 @@ const query = { }; class BasicLayout extends React.PureComponent { - static childContextTypes = { - location: PropTypes.object, - breadcrumbNameMap: PropTypes.object, - }; - getChildContext() { + getContext() { const { location, routerData, menuData } = this.props; return { location, @@ -165,10 +161,12 @@ class BasicLayout extends React.PureComponent { {params => ( -
- {layout} - -
+ +
+ {layout} + +
+
)}
diff --git a/src/layouts/MeunContext.js b/src/layouts/MeunContext.js new file mode 100644 index 00000000..860f1068 --- /dev/null +++ b/src/layouts/MeunContext.js @@ -0,0 +1,3 @@ +import { createContext } from 'react'; + +export default createContext(); diff --git a/src/layouts/PageHeaderLayout.js b/src/layouts/PageHeaderLayout.js index 74161279..c6e3f32d 100644 --- a/src/layouts/PageHeaderLayout.js +++ b/src/layouts/PageHeaderLayout.js @@ -3,11 +3,16 @@ import { Link } from 'dva/router'; import PageHeader from '../components/PageHeader'; import GridContent from './GridContent'; import styles from './PageHeaderLayout.less'; +import MeunContext from './MeunContext'; export default ({ children, wrapperClassName, top, ...restProps }) => (
{top} - + + {value => { + return ; + }} + {children ? (
{children} -- GitLab