-
Notifications
You must be signed in to change notification settings - Fork 0
wrapDynamicHook
Александр edited this page Jan 2, 2024
·
2 revisions
export function wrapDynamicHook<T extends (...args: any[]) => any>(hook: T): ((argsGetter: () => Parameters<T>) => () => ReturnType<T>)
Wraps the original hook. Allows you to use it in afc
components.
The return value is calculated every render (dynamic hook).
import { afc, wrapDynamicHook } from 'react-afc'
import { externalHook } from './hooks'
const dynamicHook = wrapDynamicHook(externalHook)
function Component(props) {
let dynamicArgument = 5
const getDynResult = dynamicHook(() => [dynamicArgument])
return () => (
<p>Dynamic value: {getDynResult()}</p>
)
}
export default afc(Component)
Component
Lifecycle
State
Redux
Other