Commit 656db95d authored by Shen Chang's avatar Shen Chang

fix(Fix KeepAlive not in Provider without prompting):

parent 0d0407e0
import React from 'react'; import React from 'react';
import Comment from './Comment'; import Comment from './Comment';
import {LIFECYCLE, ICache, ICacheItem} from './Provider'; import {LIFECYCLE, ICache, ICacheItem} from './Provider';
import {warn} from '../utils/debug';
import findDOMNodeByFiberNode from '../utils/findDOMNodeByFiberNode'; import findDOMNodeByFiberNode from '../utils/findDOMNodeByFiberNode';
interface IConsumerProps { interface IConsumerProps {
...@@ -18,15 +17,6 @@ class Consumer extends React.PureComponent<IConsumerProps> { ...@@ -18,15 +17,6 @@ class Consumer extends React.PureComponent<IConsumerProps> {
private identification: string = this.props.identification; private identification: string = this.props.identification;
constructor(props: IConsumerProps, ...args: any) {
super(props, ...args);
const {cache, setCache, children} = props;
if (!cache || !setCache) {
warn('[React Keep Alive] You should not use <KeepAlive> outside a <Provider>.');
}
React.Children.only(children);
}
public componentDidMount() { public componentDidMount() {
const { const {
setCache, setCache,
......
...@@ -173,6 +173,18 @@ export default function keepAliveDecorator<P = any>(Component: React.ComponentTy ...@@ -173,6 +173,18 @@ export default function keepAliveDecorator<P = any>(Component: React.ComponentTy
private lifecycle = LIFECYCLE.MOUNTED; private lifecycle = LIFECYCLE.MOUNTED;
constructor(props: ITriggerLifecycleContainerProps, ...args: any) {
super(props, ...args);
const {
_keepAliveContextProps: {
cache,
},
} = props;
if (!cache) {
warn('[React Keep Alive] You should not use <KeepAlive> outside a <Provider>.');
}
}
public componentDidMount() { public componentDidMount() {
if (!this.ifStillActivate) { if (!this.ifStillActivate) {
this.activate(); this.activate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment