Fix isEmpty (#1464)

This commit is contained in:
Xiliang Chen 2019-08-02 09:59:19 +12:00 committed by Jaco Greeff
parent ca24cb8a4e
commit 84f1fe4701
2 changed files with 6 additions and 8 deletions

View File

@ -14,14 +14,12 @@ type Props = CollectionProps;
type State = CollectionState;
class CardGrid extends Collection<Props, State> {
public static getDerivedStateFromProps ({ children, headerText }: Props): State {
const isEmpty = !children || (Array.isArray(children) && !children.length);
public static getDerivedStateFromProps (props: Props): State {
const state = super.getDerivedStateFromProps(props);
return {
isEmpty: isEmpty,
showHeader: isEmpty
? !!headerText
: true
...state,
showHeader: !state.isEmpty || !!props.headerText
};
}

View File

@ -53,9 +53,9 @@ export default class Collection<P extends CollectionProps, S extends CollectionS
return !children || (Array.isArray(children) && children.length === 0);
}
public static getDerivedStateFromProps ({ children }: CollectionProps): Pick<any, never> {
public static getDerivedStateFromProps ({ isEmpty, children }: CollectionProps): CollectionState {
return {
isEmpty: Collection.isEmpty(children)
isEmpty: isEmpty === undefined ? Collection.isEmpty(children) : isEmpty
};
}