Uncaught TypeError: Cannot read properties of undefined (reading ‘refs’) in React Js using NX monorepo

Getting this error while closing the modal from closeModal component. I have written path replace using history.push() function.

Ex.

const OnClose = () =>{
     history.push({
  pathname: "/dashboard"
})
}

Uncaught TypeError: Cannot read properties of undefined (reading 'refs')
        at detach (chunk-Q6I74RLG.js?v=00eb7286:3078:3)
        at chunk-Q6I74RLG.js?v=00eb7286:3150:9
        at chunk-Q6I74RLG.js?v=00eb7286:3105:9
        at safelyCallDestroy (chunk-E6XXLY7I.js?v=00eb7286:16748:13)
        at commitHookEffectListUnmount (chunk-E6XXLY7I.js?v=00eb7286:16875:19)
        at commitPassiveUnmountOnFiber (chunk-E6XXLY7I.js?v=00eb7286:18232:17)
        at commitPassiveUnmountEffects_complete (chunk-E6XXLY7I.js?v=00eb7286:18213:15)
        at commitPassiveUnmountEffects_begin (chunk-E6XXLY7I.js?v=00eb7286:18204:15)
        at commitPassiveUnmountEffects (chunk-E6XXLY7I.js?v=00eb7286:18169:11)
        at flushPassiveEffectsImpl (chunk-E6XXLY7I.js?v=00eb7286:19489:11)
        at flushPassiveEffects (chunk-E6XXLY7I.js?v=00eb7286:19447:22)
        at performSyncWorkOnRoot (chunk-E6XXLY7I.js?v=00eb7286:18868:11)
        at flushSyncCallbacks (chunk-E6XXLY7I.js?v=00eb7286:9119:30)
        at commitRootImpl (chunk-E6XXLY7I.js?v=00eb7286:19432:11)
        at commitRoot (chunk-E6XXLY7I.js?v=00eb7286:19277:13)
        at finishConcurrentRender (chunk-E6XXLY7I.js?v=00eb7286:18805:15)
    
    **The above error occurred in the <CloseModal> component.**