kibana/packages/kbn-shared-ux-utility
Marco Antonio Ghiani e0f7eab37d
[Shared UX] Extract dynamic utility for lazy loading only (#175422)
## 📓 Summary

This work extracts the utility function `dynamic`, previously duplicated
in the `log_explorer` and `logs_shared` plugins, into the
`@kbn/shared-ux-utility` package.

The component is purely dedicated to lazy loading a component reducing
the noise created by React.lazy+Suspense, here are some usage examples
from the docs:

```tsx
// Lazy load a component
const Header = dynamic(() => import('./components/header'))
// Lazy load a component and use a fallback component while loading
const Header = dynamic(() => import('./components/header'), {fallback: <EuiLoadingSpinner />})
// Lazy load a named exported component
const MobileHeader = dynamic<MobileHeaderProps>(() => import('./components/header').then(mod => ({default: mod.MobileHeader})))

function App () {
  return <Header />
}
```

The component is tested and documented to ensure the lazy loading is
performed:

```txt
dynamic
  ✓ should create a lazy loaded component starting from a dynamic default import
  ✓ should create a lazy loaded component starting from a dynamic named import
  ✓ should accept an optional "fallback" node to display while loading the component
  the created lazy loaded component
    ✓ should forward the ref property if provided
    ✓ should be properly typed respecting the original properties contract
```

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-01-29 10:56:21 +01:00
..
src [Shared UX] Extract dynamic utility for lazy loading only (#175422) 2024-01-29 10:56:21 +01:00
index.ts [Shared UX] Extract dynamic utility for lazy loading only (#175422) 2024-01-29 10:56:21 +01:00
jest.config.js [Shared UX] Extract dynamic utility for lazy loading only (#175422) 2024-01-29 10:56:21 +01:00
kibana.jsonc [codeowners] rename global experience to @elastic/appex-sharedux 2023-01-18 10:02:49 -07:00
package.json flag packages without side effects (#173351) 2023-12-19 02:46:39 -07:00
README.mdx [api-docs] follow the correct schema for frontmatter (#138348) 2022-08-10 17:17:50 -05:00
setup_tests.ts [Shared UX] Extract dynamic utility for lazy loading only (#175422) 2024-01-29 10:56:21 +01:00
tsconfig.json Integrate Event-Based Telemetry in KibanaErrorBoundary (#169895) 2023-11-03 12:55:00 -07:00

---
id: kibSharedUXUtility
slug: /kibana-dev-docs/shared-ux/packages/kbn-shared-ux-utility
title: Shared UX Utilities
description: The `@kbn/shared-ux-utility` package contains a set of React, DOM and other utilities.
date: 2022-03-11
tags: ['kibana', 'dev', 'sharedUX']
---

## About Shared UX Utility

At present, this package is currently a "catch-all" for universally-shared utilities.  View the specific documentation for each utility for 

> Important: do not add new utilities to this package without considering if a different home is more appropriate.  Reach out to the Shared UX team for help.