-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
40 lines (32 loc) · 787 Bytes
/
App.js
File metadata and controls
40 lines (32 loc) · 787 Bytes
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
/* eslint-disable no-underscore-dangle */
'use strict';
const App = require('next/app').default;
const { createContext, createElement } = require('react');
const { Provider, Consumer } = createContext();
async function getInitialProps({ ctx, ...rest }) {
const cotype =
global.__COTYPE_NEXT_DATA__ ||
(global.__NEXT_DATA__ ? global.__NEXT_DATA__.props.cotype : {});
return {
...(await App.getInitialProps({
ctx: {
...ctx,
cotype,
},
...rest,
})),
cotype,
};
}
class CotypeApp extends App {
render() {
return createElement(
Provider,
{ value: this.props.cotype },
super.render(),
);
}
}
CotypeApp.getInitialProps = getInitialProps;
CotypeApp.Context = Consumer;
module.exports = CotypeApp;