-
Notifications
You must be signed in to change notification settings - Fork 0
/
_app.tsx
46 lines (39 loc) · 1.18 KB
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react'
import { Container, NextAppContext, AppProps, DefaultAppIProps } from 'next/app'
import { Model } from 'react-model'
import Layout from '../components/layout'
import { models, getInitialState, Models } from '../model/index.model'
import { RouterProps } from 'next/router'
let persistModel: Models
interface ModelsProps {
initialModels: Models
persistModel: Models
}
const MyApp = (
props: AppProps & DefaultAppIProps & RouterProps & ModelsProps
) => {
if ((process as any).browser) {
// First come in: initialModels
// After that: persistModel
persistModel = props.persistModel || Model(models, props.initialModels)
}
const { Component, pageProps, router } = props
return (
<Container>
<Layout>
<Component {...pageProps} />
</Layout>
</Container>
)
}
MyApp.getInitialProps = async (context: NextAppContext) => {
if (!(process as any).browser) {
const initialModels = context.Component.getInitialProps
? await context.Component.getInitialProps(context.ctx)
: await getInitialState({ modelName: 'Home' })
return { initialModels }
} else {
return { persistModel }
}
}
export default MyApp