UNPKG

3.83 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="react" />
3import App, { AppContext, AppInitialProps } from 'next/app';
4import { Store } from 'redux';
5import { GetServerSideProps, GetServerSidePropsContext, GetStaticProps, GetStaticPropsContext, NextComponentType, NextPageContext } from 'next';
6/**
7 * Quick note on Next.js return types:
8 *
9 * Page.getInitialProps https://nextjs.org/docs/api-reference/data-fetching/getInitialProps
10 * as-is
11 *
12 * App.getInitialProps: AppInitialProps https://nextjs.org/docs/advanced-features/custom-app
13 * {pageProps: any}
14 *
15 * getStaticProps https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation
16 * {props: any}
17 *
18 * getServerSideProps https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering
19 * {props: any}
20 */
21export declare const HYDRATE = "__NEXT_REDUX_WRAPPER_HYDRATE__";
22export declare type MakeStore<S extends Store> = (context: Context) => S;
23export interface InitStoreOptions<S extends Store> {
24 makeStore: MakeStore<S>;
25 context?: Context;
26}
27export declare const createWrapper: <S extends Store<any, import("redux").AnyAction>>(makeStore: MakeStore<S>, config?: Config<S>) => {
28 getServerSideProps: <P extends {} = any>(callback: GetServerSidePropsCallback<S, P>) => GetServerSideProps<P, import("querystring").ParsedUrlQuery, import("next").PreviewData>;
29 getStaticProps: <P_1 extends {} = any>(callback: GetStaticPropsCallback<S, P_1>) => GetStaticProps<P_1, import("querystring").ParsedUrlQuery, import("next").PreviewData>;
30 getInitialAppProps: <P_2 extends {} = any>(callback: AppCallback<S, P_2>) => GetInitialAppProps<P_2>;
31 getInitialPageProps: <P_3 extends {} = any>(callback: PageCallback<S, P_3>) => ((context: NextPageContext<any>) => any) | undefined;
32 withRedux: (Component: NextComponentType | App | any) => {
33 (props: any): JSX.Element;
34 displayName: string;
35 getInitialProps: any;
36 };
37 useWrappedStore: ({ initialState: giapState, initialProps, ...props }: any, displayName?: string) => {
38 store: S;
39 props: any;
40 };
41};
42declare const _default: <S extends Store<any, import("redux").AnyAction>>(makeStore: MakeStore<S>, config?: Config<S>) => (Component: any) => {
43 (props: any): JSX.Element;
44 displayName: string;
45 getInitialProps: any;
46};
47export default _default;
48export declare type Context = NextPageContext | AppContext | GetStaticPropsContext | GetServerSidePropsContext;
49export interface Config<S extends Store> {
50 serializeState?: (state: ReturnType<S['getState']>) => any;
51 deserializeState?: (state: any) => ReturnType<S['getState']>;
52 debug?: boolean;
53}
54export interface WrapperProps {
55 initialProps: any;
56 initialState: any;
57}
58declare type GetInitialPageProps<P> = NextComponentType<NextPageContext, any, P>['getInitialProps'];
59declare type GetInitialAppProps<P> = ({ Component, ctx }: AppContext) => Promise<AppInitialProps & {
60 pageProps: P;
61}>;
62export declare type GetStaticPropsCallback<S extends Store, P extends {
63 [key: string]: any;
64}> = (store: S) => GetStaticProps<P>;
65export declare type GetServerSidePropsCallback<S extends Store, P extends {
66 [key: string]: any;
67}> = (store: S) => GetServerSideProps<P>;
68export declare type PageCallback<S extends Store, P> = (store: S) => GetInitialPageProps<P>;
69export declare type AppCallback<S extends Store, P> = (store: S) => GetInitialAppProps<P>;
70export declare type Callback<S extends Store, P extends {
71 [key: string]: any;
72}> = GetStaticPropsCallback<S, P> | GetServerSidePropsCallback<S, P> | PageCallback<S, P> | AppCallback<S, P>;
73declare module 'next' {
74 interface NextPageContext<S extends Store = any> {
75 /**
76 * Provided by next-redux-wrapper: The redux store
77 */
78 store: S;
79 }
80}