How to use getInitialProps in _app.js file with function component?

Solution 1:

You should be able to set it up as follows, but be aware when you have getInitialProps on your app you are blocking every page, see more details here: https://nextjs.org/docs/advanced-features/custom-app

function App({ pageProps, Component }) {
    return (
        <Layout >
            <Component {...pageProps} />
        </Layout>
    )
}

App.getInitialProps = async (appContext) => {
  // Logic goes here
}

export default App;