import { useCMS , Form } from 'tinacms' ; import { useEffect } from 'react' ; import createDecorator , { Calculation } from 'final-form-calculate' ; export function useLastEdited ( form ) { useFormDecorator ( form , { field : /.*/ , updates : { 'frontmatter.last_edited' : ( ) => new Date ( ) . toISOString ( ) , } , } ) ; } function useFormDecorator ( form , ... calculations ) { const cms = useCMS ( ) ; useEffect ( ( ) => { if ( cms . disabled ) { return ; } const decorator = createDecorator ( ... calculations ) ; return decorator ( form . finalForm ) ; } , [ form . id ] ) ; }