diff --git a/package.json b/package.json index 303aff8..8a194f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nextjs-router-events", - "version": "0.0.3", + "version": "0.0.4", "description": "A router events alternative for Next.js 13+ with app directory with the ability to prevent user navigation.", "author": "run4w4y ", "main": "dist/index.js", diff --git a/src/context.ts b/src/context.ts index cbd3727..a8938ca 100644 --- a/src/context.ts +++ b/src/context.ts @@ -3,6 +3,8 @@ import React, { useContext } from 'react' import { noop } from './util' +let requests: string[] = [] + interface FreezeRequestsContextValue { freezeRequests: string[] setFreezeRequests: React.Dispatch> @@ -19,10 +21,12 @@ export const useFreezeRequestsContext = () => { return { freezeRequests, request: (sourceId: string) => { - setFreezeRequests([...freezeRequests, sourceId]) + requests = [...requests, sourceId] + setFreezeRequests(requests) }, revoke: (sourceId: string) => { - setFreezeRequests(freezeRequests.filter((x) => x !== sourceId)) + requests = requests.filter((x) => x !== sourceId) + setFreezeRequests(requests) }, } }