UNPKG

6.69 kBTypeScriptView Raw
1/// <reference types="node" />
2import App, { AppContext, AppInitialProps } from 'next/app';
3import React from 'react';
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>;
29 getStaticProps: <P_1 extends {} = any>(callback: GetStaticPropsCallback<S, P_1>) => GetStaticProps<P_1, import("querystring").ParsedUrlQuery>;
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 new (props: any, context: any): {
34 store: S;
35 hydrate({ initialState, initialProps, ...props }: any, context: any): void;
36 shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
37 render(): JSX.Element;
38 context: any;
39 setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
40 forceUpdate(callback?: (() => void) | undefined): void;
41 readonly props: Readonly<any> & Readonly<{
42 children?: React.ReactNode;
43 }>;
44 state: Readonly<any>;
45 refs: {
46 [key: string]: React.ReactInstance;
47 };
48 componentDidMount?(): void;
49 componentWillUnmount?(): void;
50 componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
51 getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
52 componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
53 componentWillMount?(): void;
54 UNSAFE_componentWillMount?(): void;
55 componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
56 UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
57 componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
58 UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
59 };
60 displayName: string;
61 getInitialProps: any;
62 contextType?: React.Context<any> | undefined;
63 };
64};
65declare const _default: <S extends Store<any, import("redux").AnyAction>>(makeStore: MakeStore<S>, config?: Config<S>) => (Component: any) => {
66 new (props: any, context: any): {
67 store: S;
68 hydrate({ initialState, initialProps, ...props }: any, context: any): void;
69 shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
70 render(): JSX.Element;
71 context: any;
72 setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
73 forceUpdate(callback?: (() => void) | undefined): void;
74 readonly props: Readonly<any> & Readonly<{
75 children?: React.ReactNode;
76 }>;
77 state: Readonly<any>;
78 refs: {
79 [key: string]: React.ReactInstance;
80 };
81 componentDidMount?(): void;
82 componentWillUnmount?(): void;
83 componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
84 getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
85 componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
86 componentWillMount?(): void;
87 UNSAFE_componentWillMount?(): void;
88 componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
89 UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
90 componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
91 UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
92 };
93 displayName: string;
94 getInitialProps: any;
95 contextType?: React.Context<any> | undefined;
96};
97export default _default;
98export declare type Context = NextPageContext | AppContext | GetStaticPropsContext | GetServerSidePropsContext;
99export interface Config<S extends Store> {
100 serializeState?: (state: ReturnType<S['getState']>) => any;
101 deserializeState?: (state: any) => ReturnType<S['getState']>;
102 debug?: boolean;
103}
104export interface WrapperProps {
105 initialProps: any;
106 initialState: any;
107}
108declare type GetInitialPageProps<P> = NextComponentType<NextPageContext, any, P>['getInitialProps'];
109declare type GetInitialAppProps<P> = ({ Component, ctx }: AppContext) => Promise<AppInitialProps & {
110 pageProps: P;
111}>;
112export declare type GetStaticPropsCallback<S extends Store, P> = (store: S) => GetStaticProps<P>;
113export declare type GetServerSidePropsCallback<S extends Store, P> = (store: S) => GetServerSideProps<P>;
114export declare type PageCallback<S extends Store, P> = (store: S) => GetInitialPageProps<P>;
115export declare type AppCallback<S extends Store, P> = (store: S) => GetInitialAppProps<P>;
116export declare type Callback<S extends Store, P> = GetStaticPropsCallback<S, P> | GetServerSidePropsCallback<S, P> | PageCallback<S, P> | AppCallback<S, P>;
117declare module 'next' {
118 interface NextPageContext<S extends Store = any> {
119 /**
120 * Provided by next-redux-wrapper: The redux store
121 */
122 store: S;
123 }
124}