Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: make useReducerWithDevtools noop on server #41019

Merged
merged 1 commit into from Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/next/client/components/use-reducer-with-devtools.ts
Expand Up @@ -104,7 +104,20 @@ function devToolReducer(
}
}

export function useReducerWithReduxDevtools(
function useReducerWithReduxDevtoolsNoop(
fn: typeof reducer,
initialState: ReturnType<typeof reducer>
): [
ReturnType<typeof reducer>,
Dispatch<ReducerAction<typeof reducer>>,
() => void
] {
const [state, dispatch] = useReducer(fn, initialState)

return [state, dispatch, () => {}]
}

function useReducerWithReduxDevtoolsImpl(
fn: typeof reducer,
initialState: ReturnType<typeof reducer>
): [
Expand Down Expand Up @@ -158,3 +171,8 @@ export function useReducerWithReduxDevtools(
}, [state])
return [state, dispatch, sync]
}

export const useReducerWithReduxDevtools =
typeof window !== 'undefined'
? useReducerWithReduxDevtoolsImpl
: useReducerWithReduxDevtoolsNoop