I have made a HOC for showing a loading modal when my component is loading.
export const withLoading = (Component) => {
return function HOCLoading(props) {
const [isLoading, setIsLoading] = useState(false)
return (
<>
<Component
{...props}
isLoading={isLoading}
setIsLoading={setIsLoading}
/>
<Loading isLoading={isLoading} />
</>
)
}
}
And I'm using it as
export default withLoading(MyComponent)
It was working fine until I realize that the navigationOptions
stopped working, which is obvious because withLoading
return a component that don't have navigationOptions
, so my workaround was.
const LoadingMyComponent = withLoading(MyComponent)
And then set navigationOptions
to LoadingMyComponent
.
But this looks bad and doesn't make it easier than having a state for loading and rendering Loading
.
Is there a way to transform this HOC into a react hooks or do something that I don't mess with the navigationOptions
and also encapsulates the Loading
component and logic?