Skip to content

useFabric Hook

The useFabric composable accesses the Fabric context containing metadata and lifecycle control within Fabric components.

Use useFabric when: You need to access metadata from the Fabric component or exit the rendering process.

Perfect for: Shared configuration, version info, global state, early exit conditions.

Usage

Access Fabric metadata and lifecycle control from within components.

Example: Access metadata from Fabric context.

ts
import { 
useFabric
} from '@kubb/fabric-core'
const
fabric
=
useFabric
()
console
.
log
(
fabric
.
meta
)
fabric
.
exit
() // exit

Return Value

Returns the current Fabric context containing:

metaTMetaMetadata passed to Fabric component
exit() => voidFunction to exit the render

When to Use

Use useFabric when you need to:

  • Access metadata defined in the Fabric component
  • Exit the rendering process early
  • Share global state across components

Examples

Access Metadata

tsx
import { 
useFabric
} from '@kubb/fabric-core'
function
MyComponent
() {
const {
meta
} =
useFabric
<{
version
: string }>()
return `// Version: ${
meta
.
version
}`
}

Exit Early

ts
import { 
useFabric
} from '@kubb/fabric-core'
function
ConditionalComponent
({
shouldRender
}: {
shouldRender
: boolean }) {
const {
exit
} =
useFabric
()
if (!
shouldRender
) {
exit
()
return null } return 'Content' }

See Also

Released under the MIT License.