Fix isEmpty (#1464)
This commit is contained in:
parent
ca24cb8a4e
commit
84f1fe4701
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user