0.2.3 • Published 1 year ago

@modular-component/with-lifecycle v0.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@modular-component/with-lifecycle

Basic stage allowing to save the result of a custom hook to a lifecycle argument passed down to further stages. The lifecycle hook receives the previous argument map as parameter, and can therefore use props or any other injected argument.

Usage

import { ModularComponent } from '@modular-component/core'
import { lifecycle } from '@modular-component/with-lifecycle'

const MyComponent = ModularComponent()
  .with(lifecycle(({ props }) => {
    // Write component state & logic here
  }))
  .with(render(({ props, lifecycle }) => (
    // Use computed lifecycle in the render phase
  )))

Implementation

with(lifecycle) receives a function taking the current arguments map as parameter. It uses this function as the stage hook directly:

import { ModularStage } from '@modular-component/core'

export function lifecycle<Args extends {}, Return>(
  useLifecycle: (args: Args) => Return,
): ModularStage<'lifecycle', (args: Args) => Return> {
  return { field: 'lifecycle', useStage: useLifecycle }
}
0.2.3

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago