Reactjs 如何通过HOC显示加载程序?
我想使用HOC组件来显示正在加载的动画。某些组件具有“isLoading”属性,而其他组件具有“isPending”属性。我如何给HOC一个defauult道具,让它显示加载程序Reactjs 如何通过HOC显示加载程序?,reactjs,Reactjs,我想使用HOC组件来显示正在加载的动画。某些组件具有“isLoading”属性,而其他组件具有“isPending”属性。我如何给HOC一个defauult道具,让它显示加载程序 isLoading isPending isNotReady ... const WithLoader = ControlledComponent => ({ isPending, ...props }) => { 这应该行得通。 假设加载组件名称为load const WithLoader = C
isLoading
isPending
isNotReady
...
const WithLoader = ControlledComponent => ({ isPending, ...props }) => {
这应该行得通。
假设加载组件名称为load
const WithLoader = ControlledComponent => ({ isLoading, isPending, isNotReady, ...props }) => {
return (isPending || isLoading || isNotReady) ?
<Loading />
:
<ControlledComponent {...props} />;
}
constwithloader=ControlledComponent=>({isLoading,isPending,isNotReady,…props})=>{
返回(isPending | | isLoading | | isNotReady)?
:
;
}
这应该行得通。
假设加载组件名称为load
const WithLoader = ControlledComponent => ({ isLoading, isPending, isNotReady, ...props }) => {
return (isPending || isLoading || isNotReady) ?
<Loading />
:
<ControlledComponent {...props} />;
}
constwithloader=ControlledComponent=>({isLoading,isPending,isNotReady,…props})=>{
返回(isPending | | isLoading | | isNotReady)?
:
;
}
您可以使用Loader创建更高阶的组件,如下所示:
export const with loader=controlled组件=>({
isLoading、isPending、isNotReady、children、,
})=>((isLoading | | isPending | | isNotReady)?
:{儿童}
);代码>您可以使用Loader创建更高阶的组件,如下所示:
export const with loader=controlled组件=>({
isLoading、isPending、isNotReady、children、,
})=>((isLoading | | isPending | | isNotReady)?
:{儿童}
);代码>