Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap _app.js within multiple providers?

I was wondering if it's possible and how to wrap my top level page _app.js within Redux provider considered I already wrapped it with Next-auth provider like:

import React from "react"
import { Provider } from 'next-auth/client'
import '../public/global.scss'

export default function App ({ Component, pageProps }) {
  return (
      <Provider
        options={{
          clientMaxAge: 0,
          keepAlive: 5 * 60
        }}
        session={pageProps.session} >
        <Component {...pageProps} />
      </Provider>
  )
}

The issue is that when I try to add also Redux <Provider .. it says Provider is already defined.

like image 254
m4tt Avatar asked Nov 23 '25 22:11

m4tt


1 Answers

You can rename the redux provider named import using as.

import React from "react"
import { Provider as NextAuthProvider } from 'next-auth/client'
import { Provider as ReduxProvider } from 'react-redux'
import '../public/global.scss'

export default function App ({ Component, pageProps }) {
    return (
        <ReduxProvider>
            <NextAuthProvider
                options={{
                    clientMaxAge: 0,
                    keepAlive: 5 * 60
                }}
                session={pageProps.session} >
                <Component {...pageProps} />
            </NextAuthProvider>
        </ReduxProvider>
    )
}
like image 198
juliomalves Avatar answered Nov 26 '25 12:11

juliomalves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!