Next.js project with NativeBase next-adapter
is a React framework that provides simple page-based routing as well as server-side rendering. To use Next.js with NativeBase for web we recommend that you use a library called
to handle the configuration and integration of the tools.
Install dev dependencies.
Re-export the custom Document component in the pages/_document.js file of your Next.js project.
This will ensure react-native-web styling works.
Wraps all the css in style tag on server side (thus preventing css flicker issue)
Or you can create the file using following command mkdir pages; touch pages/_document.js
Update your pages/_document.js with the below content.
export { default } from '@native-base/next-adapter/document';
Update next.config.json with below code
const { withNativebase } = require('@native-base/next-adapter');
module.exports = withNativebase({
dependencies: [
],
});
Run the Hello world example
Replace the code below in your pages/_app.js
import '../styles/globals.css';
import { NativeBaseProvider } from 'native-base';
function MyApp({ Component, pageProps }) {
return (
<NativeBaseProvider>
<Component {...pageProps} />
</NativeBaseProvider>
);
}
export default MyApp;
and put this in your pages/index.js
import React from 'react';
import { Box } from 'native-base';
export default function App() {
return <Box>Hello world</Box>;
}