Giter VIP home page Giter VIP logo

react-native-style-guide's Introduction

React Native StyleGuide + Best Practices() {

A proposed style + best practices for creating React-Native mobile apps used internally at GuavaPass.com


This guideline is an extension to the AirBnB style guide for javascript and react

Table of Contents

  1. Libraries
  2. Folder Structure

Libraries

Folder Structure

  • To encourage reuse of style between a react app and a react native app I propose keeping the same folder structure as is common with other react-redux apps.

This folder structure should reflect something similar to:

.
├── index.android.js 
├── index.ios.js
├── package.json
├── android
├── ios
├── node_modules
├── src
   ├── actions
   │   ├── exampleActionsCreators.js
   ├── components
   │   └── ExampleComponent
   │       │   └── ExampleComponent.android.jsx
   │       │   └── ExampleComponent.ios.jsx
   ├── constants
   │   ├── exampleConstants.js
   ├── containers
   │   └── ExampleContainer
   │           └── ExampleContainer.android.jsx
   │           └── ExampleContainer.ios.jsx
   ├── layout
   │   └── layout.android.jsx
   │   └── layout.ios.jsx
   ├── reducers
   │   ├── index.js
   ├── routes
   │   └── routes.jsx
   └── store
       └── store.js

This structure should look fairly familiar to anyone with experience developing an app using redux, but lets quickly cover the conventions behind the folder structure and the conventions used above.

Actions

ActionCreators are responsible for converting your application’s data to a format of some remote API and/or updating the state of the store. It is responsible for both making the requests and handling responses.

Actions are simply stored in this folder usually related to some subset of the store, the convention it to name them -, eg Lesson-Create, Booking-Confirm. The idea behind this is that you want to categorize then by object type, rather than the action type.

Containers

First step read Dan Abramov's post about the different type of components

Containers are simply Smart Components. Smart components are components that are concerned with managing the flow of data to other dumb child components. They are responsible for connecting with the store to pass the information to children, provide actions and callbacks for children to use.

These containers should be the only components that we reference in our routes

Inside of these containers we should:

  • Generate action creators for children
    • This allows the dumb child components to not be responsible for any logic, and it should simply reference an action passed down from the container
    • The container is also responsible for handling the suitable manipulation of data and forwarding that on to the appopriate action creator.
  • Should NOT contain any rendering of markup, except dump components. This is to seperate the concerns of containers vs components and we should avoid even wrapping our components in <div></div> tags

react-native-style-guide's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.