-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove redux devtools from router reducer
- Loading branch information
Showing
4 changed files
with
39 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
packages/next/src/client/components/use-reducer-with-devtools.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Dispatch } from 'react' | ||
import React, { use } from 'react' | ||
import { useCallback } from 'react' | ||
import type { | ||
AppRouterState, | ||
ReducerActions, | ||
ReducerState, | ||
} from './router-reducer/router-reducer-types' | ||
import type { AppRouterActionQueue } from '../../shared/lib/router/action-queue' | ||
import { isThenable } from '../../shared/lib/is-thenable' | ||
|
||
export function useUnwrapState(state: ReducerState): AppRouterState { | ||
// reducer actions can be async, so sometimes we need to suspend until the state is resolved | ||
if (isThenable(state)) { | ||
const result = use(state) | ||
return result | ||
} | ||
|
||
return state | ||
} | ||
|
||
export function useReducer( | ||
actionQueue: AppRouterActionQueue | ||
): [ReducerState, Dispatch<ReducerActions>] { | ||
const [state, setState] = React.useState<ReducerState>(actionQueue.state) | ||
|
||
const dispatch = useCallback( | ||
(action: ReducerActions) => { | ||
actionQueue.dispatch(action, setState) | ||
}, | ||
[actionQueue] | ||
) | ||
|
||
return [state, dispatch] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters