Skip to content

useLifecycle Hook

The useLifecycle composable provides lifecycle control including the ability to exit rendering early or with errors.

Use useLifecycle when: You need to stop rendering early based on conditions or exit with errors.

Perfect for: Validation failures, conditional generation, error handling.

Usage

Exit the rendering process programmatically from within components.

Example: Exit rendering early.

tsx
import { 
useLifecycle
} from '@kubb/fabric-core'
function
MyComponent
() {
const {
exit
} =
useLifecycle
()
exit
()
return null }

Return Value

PropertyTypeDescription
exit(error?: Error) => voidFunction to stop rendering and exit the process

When to Use

Use useLifecycle when you need to:

  • Stop the rendering process early
  • Exit with an error condition
  • Implement conditional rendering logic that may abort the generation

Examples

Exit with Error

tsx
import { 
useLifecycle
} from '@kubb/fabric-core'
function
MyComponent
({
data
}: {
data
?: unknown }) {
const {
exit
} =
useLifecycle
()
if (!
data
) {
exit
(new
Error
('Data is required'))
return null } return null }

See Also

Released under the MIT License.