From cf635d59139fa5c6fac419e9453244e48a904b68 Mon Sep 17 00:00:00 2001 From: hashcode55 Date: Tue, 27 Jun 2017 01:19:56 +0530 Subject: [PATCH] async-await in getInitialProps --- components/ensureSignedIn.js | 4 ++-- components/injectEnvironmentVar.js | 4 ++-- components/injectSession.js | 4 ++-- components/wrapWithLayout.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/ensureSignedIn.js b/components/ensureSignedIn.js index e62a8af..2437f8a 100644 --- a/components/ensureSignedIn.js +++ b/components/ensureSignedIn.js @@ -9,9 +9,9 @@ import React from 'react' const ensureSignedIn = Page => { return class EnsureSignedIn extends React.Component { - static getInitialProps (context) { + static async getInitialProps (context) { // If the page has a prop fetcher invoke it - return Page.getInitialProps ? Page.getInitialProps(context) : {} + return Page.getInitialProps ? await Page.getInitialProps(context) : {} } constructor (props) { diff --git a/components/injectEnvironmentVar.js b/components/injectEnvironmentVar.js index afc21e5..a8b0172 100644 --- a/components/injectEnvironmentVar.js +++ b/components/injectEnvironmentVar.js @@ -21,9 +21,9 @@ const injectEnvironmentVar = varName => Page => { } return class InjectEnvironmentVar extends React.Component { - static getInitialProps (context) { + static async getInitialProps (context) { // Get the page's own initial props - const initialProps = Page.getInitialProps ? Page.getInitialProps(context) : {} + const initialProps = Page.getInitialProps ? await Page.getInitialProps(context) : {} // Dig the specified environment variables up from the // appropriate sources const env = process.browser ? global.__next_env : process.env diff --git a/components/injectSession.js b/components/injectSession.js index 89c2d41..b3dd48a 100644 --- a/components/injectSession.js +++ b/components/injectSession.js @@ -25,9 +25,9 @@ const injectSession = Page => { this.state = {} } - static getInitialProps (context) { + static async getInitialProps (context) { // Get the page's own initial props - const initialProps = Page.getInitialProps ? Page.getInitialProps(context) : {} + const initialProps = Page.getInitialProps ? await Page.getInitialProps(context) : {} // Dig the session out of localstorage (on client) or the request (on // server) diff --git a/components/wrapWithLayout.js b/components/wrapWithLayout.js index ab9a8f5..21429da 100644 --- a/components/wrapWithLayout.js +++ b/components/wrapWithLayout.js @@ -5,9 +5,9 @@ import Menu from './Menu' const wrapWithLayout = Page => { return class WrapWithLayout extends React.Component { - static getInitialProps (context) { + static async getInitialProps (context) { return Page.getInitialProps - ? Page.getInitialProps(context) + ? await Page.getInitialProps(context) : {} }