rsnext/examples/with-mobx-react-lite/pages/_app.js

31 lines
763 B
JavaScript
Raw Normal View History

import App from 'next/app'
import React from 'react'
import { InjectStoreContext, initializeData } from '../store'
class MyMobxApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {}
const initialStoreData = initializeData()
// Provide the store to getInitialProps of pages
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps({ ...ctx, initialStoreData })
}
return {
pageProps,
initialStoreData,
}
}
render() {
const { Component, pageProps, initialStoreData } = this.props
return (
<InjectStoreContext initialData={initialStoreData}>
<Component {...pageProps} />
</InjectStoreContext>
)
}
}
export default MyMobxApp