Skip to main content

Platform-Specific Code

You can use different code on different platforms by specifying different file extensions.

See the tree shaking guide for more.


For a video walkthrough of using different code per-platform, see my 2021 Next.js Conf talk at about 21:53:


One example of platform-specific code is using @react-native-firebase on Native, and firebase on Web.

To see how this works, you can reference the source code from my 2022 Next.js Conf talk. Here's the Firebase section.