Socket
Socket
Sign inDemoInstall

@osamaq/react-native-template

Package Overview
Dependencies
0
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @osamaq/react-native-template

A minimal template with good architecture and common packages to let you focus on writing features right away.


Version published
Weekly downloads
18
decreased by-25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-native-template

Build Status npm downloads npm version

Template landing screen preview Reactotron preview


A minimal template with architecture and boilerplate to let you focus on writing features right away.

Preconfigured with

Contents

Documentation

Getting Started

Create a new project using the template.

  • Note: the command will fail if you have the global legacy react-native-cli installed. Make sure you uninstall it first. More info at react-native-community/cli.

RN 0.63.2

$ npx react-native init MyApp --template @osamaq/react-native-template

Optional Steps

Connect To Sentry

This template comes with Sentry, but its disabled until you connect your account.

To connect your account:

$ cd MyApp/

# For MacOS
$ npx sentry-wizard -i reactNative -p ios android

# Other Platforms
$ npx sentry-wizard -i reactNative -p android

Insert your sentry DSN in each .env file (dev, staging and production) and you're all done.

Install Reactotron Flipper Plugin

This allows you to use Reactotron within Flipper.

Flipper -> Manage Plugins -> Install Plugins -> flipper-plugin-reactotron

Libraries

Let's briefly go over the benefit of each library included in this template.

TypeScript

For type safety ¯\(ツ)

But in all seriousness, if you are considering this template I assume you are a TypeScript fan. If you happen to be a JavaScript user, this template might be overwhelming. If you would like to start learning TypeScript, I suggest bootstrapping with this instead react-native-community/react-native-template-typescript so you can learn at your own pace.

SWR

This library simplifies data fetching and cache management. It allows you to easily show cached data, while the new data is being loaded from the API.

  • Caveat: currently it only supports in-memory caching for data.

  • Alternative: React Query/Apollo.

apisauce

Its a wrapper around axios with extended functionality. I'm happy with its API and I like the problem matcher.

Redux/Redux Toolkit

I'm happy using Redux Toolkit. It's a lot more concise now and I enjoy the redux ecosystem of plugins.

SWR reduces our dependency on Redux for global state. And sometimes React Navigation can be used to send data to the next screen. I try to leverage these two before reaching out to global state.

If you prefer something else, remove redux and go with that. Do not waste time trying a new state management solution.

Redux Observable

This is used alongside Redux for complex background work. Most people will rarely need to use something like this. In fact, if you aren't sure, just remove it (also uninstall its dependency, rxjs).

React Navigation

It is the most popular navigation library. For most apps, this is the best choice.

Reactotron/Flipper

Using this template there will be two main deubgging tools in your toolbelt. Reactotron and Flipper.

I mainly use Reactotron for reading API calls, asyncstorage operations, redux actions etc. It organizes everything in a neat way. It also has a killer image overlay feature, which allows you to get the UI design pixel prefect.

Flipper could be used for lower level debugging, such as viewing your database or React component tree. There is also a Flipper plugin for using Reactotron within it, so you only need to start one application.

Flipper -> Manage Plugins -> Install Plugins -> flipper-plugin-reactotron

Sentry

Benefitial in debugging issues that occur only in release builds. You can view error stack traces for unhandled exceptions. You can also choose to log specific errors in some catch blocks to study how often they occur in production.

In this template, there is a custom Redux middleware that adds Redux actions as breadcrumbs to Sentry reports for even easier debugging.

This is similar to redux-sentry-middleware but I've yet to test that one.

react-native-bootsplash

Works great for controlling your splash screen.

react-native-svg

Prefer using SVG over images all the time (remember to optimize your SVGs).

react-native-config

If you have different development, staging and production variables, this library is very helpful. It allows you to declare environment variables that can be accessed by all 3 sides (android, ios, JavaScript).

Android: by default, running react-native run-android will use the development .env file. To load .env.staging we must use:

ENVFILE=.env.staging react-native run-android

Note: the above works on MacOS. For windows its a bit different. See Different Environments.

iOS: two additional schemes are created in the Xcode project for staging and production. The corresponding .env file is set via the scheme's pre-action:

Scheme's pre-action setting the .env file

NPM scripts for running the app with the desired configuration are included for convenience.

Reanimated/Redash

Necessary when creating complex gesture based animations that are highly performant. Redash contains boilerplate helpers for Reanimated.

AsyncStorage

For caching simple data such as user perferences.

FastImage

Drop in replacement for the <Image/> component. I've found this to give a performance boost on android when rendering many images.

Detox

For end-to-end testing.

Mirage JS

Mirage is an in-memory server for intercepting API calls and returning whatever data you want. Very useful for developing before the backend is deployed, and for confirming how the app reacts to different API call outcomes.

Fastlane

Fastlane community has an endless amount of mobile development automation plugins. I currently use it mainly for automatic versioning, and often for deploying to Microsoft's App Center in one command.

This template also has a fastlane command for adding version badges to app icons. Useful outside of production as it makes it easier for QA to tell the app version.

App icon with version badge

If you appreciate those libraries and find them useful, please consider supporting them.

Directory Structure

root
├── __tests__
├── android
├── e2e
├── fastlane
├── ios
├── scripts
└── src
    └── common
    |   ├── assets
    |   ├── components
    |   ├── exceptions
    |   ├── helpers
    |   ├── hooks
    |   ├── theme
    |   └── types
    └── features
    |   ├── error-boundary
    |   ├── home
    |   ├── landing
    |   └── navigation
    └── redux
    |   ├── middleware
    |   └── slices
    └── services
        ├── cache
        ├── navigation
        └── network
            ├── github
            └── mock

Quick Overview

Quickly get an idea about each folder's role.

DirectoryShort Description
rootRoot directory. Contains many configuration files and all other folders.
__tests__(Default; as per official template)
androidAndroid project. Includes modifications to integrate libraries.
e2eDetox end-to-end tests and configurations.
fastlaneUseful fastlane automation scripts.
iosiOS project. Includes modifications to integrate libraries.
scriptsHandy node scripts for code generation.
srcMost of the app's code is here.
commonShared code between different features.
assetsShared images, fonts etc.
componentsShared React components.
exceptionsShared custom exceptions.
helpersShared utlities.
hooksShared hooks.
themeShared styles; app's theme.
typesShared general types.
featuresFeature directories.
error-boundaryRoot error boundary.
homeHome screen. Has simple data fetching and global state examples.
landingTemplate's initial screen.
navigationContains a simple stack navigator.
reduxRedux integration.
middlewareRedux custom middleware. For now, a simple Sentry breadcrumb logger.
slicesRedux state slices.
servicesApp's services.
cacheCache service; AsyncStorage wrapper.
navigationNavigation service (navigate from outside React components).
networkNetworking related services.
githubExample GitHub API client (REST).
mockMirageJS in-memory server for mocking backend APIs.

If you would like to learn more without going through the codebase, read the file walkthrough here.

Credits

This template is modified from react-native-typescript-template. Thank you ❤️

Keywords

FAQs

Last updated on 23 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc