-
Notifications
You must be signed in to change notification settings - Fork 0
useOnceCreated
Александр edited this page Jan 17, 2023
·
1 revision
export function useOnceCreated<T>(factory: () => T): T
Calls the passed function once. Returns its cached value.
import { afc } from 'react-afc'
import { useOnceCreated, useOnMount } from 'react-afc/compatible'
function withHardCalc() {
const bigValue = useOnceCreated(() => {/* calculations */})
useOnMount(() => {
console.log(bigValue)
})
}
const AFCComponent = afc(props => {
withHardCalc()
return () => (
<p>content</p>
)
})
function CommonComponent(props) {
// It will work the same way as in the afc component.
// Will not cause errors.
withHardCalc()
return (
<p>content</p>
)
}
Component
Lifecycle
State
Redux
Other