Table of Content
- Change Name of the Project
- Setting Up
- Features Provided
- Project Structure
- How to Make Api Calls
- React
Rename the project name to the appropriate name that you want for the project. The best way to do that is to install the package react-native-rename
Follow these steps from the documentation of react-native-rename to rename the project properly
- Clone this repo.
- Move into the project directory.
- Run
yarn install
ornpm install
to install the dependencies. - Install pods using
cd ios/ && pod install && cd ..
- For IOS Run project using
react-native run-ios
- For Android Run project using
react-native run-android
Typescript
integrated.- Linting setup.
- Prettier config added.
- husky configured.
commit-msg
andpre-commit
hooks added. -commit-msg
hook makes sure you write conventional-commit-msg -pre-commit
hook runs prettier and linting before commiting. - State managed through redux-saga
- Reactotron configured for debugging. Download the reactotron app from here. Reactotron will automatically start logging once you build your app on IOS or Android.
Top Level Directory Layout
.
|---- __tests__ Tests written for the app
|---- android Android directory (android configs)
|---- App Contains App code (Containers, Components ...)
|---- Asests Contains Fonts to be linked for the project
|---- custom_typings Custom typings for the packages without types
|---- ios Ios directory (ios setup)
|---- .prettierrc Contains prettier config for formatting
|---- commitlint.config.js Contains conventional commit config
|---- index.ts Starting point of the app
|---- react-native.config.js https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide)
|---- tsconfig.json typescript config
|---- tslint.json ts linting rules
App Directory
.
|---- Components Common Components to be used in the app
|---- Config Config files
|---- Constants Constants to be used throughout the app
|---- Containers Contains components for the screens
|---- Images Contains Image assets
|---- Lib Contains utils for the app
|---- Navigation Contains React Navigation code for screens
|---- Reducers Reducers for the app
|---- Sagas Sagas for the reducers
|---- Services Services used for the app
|---- Themes Contains design UI related things
|---- Types Contains global types
Firstly setup base url in AppConfig.ts
in Config
directory.
Pass Api
in the Action that you want to use in.
e.g
takeLatest(StartupTypes.STARTUP, startup, Api),
This Api
will be accessible in the relevant saga in the action's first argument like this.
export function* startup(api) {
...
...
}
Now Make The api call
export function* startup(api) {
try {
const apiResponse = yield api({
method: 'GET',
url: '/todos/1', // This url will get appended in the base url
});
console.log('api response ', apiResponse);
} catch (error) {
console.log('error ', error);
}
}
Import Api.ts
from the Services in whichever file you want to make the api call.
Use it like this.
import Api from '../Services/Api'; // Match your path here
api({
method: 'GET',
url: '/todos/1', // This url will get appended in the base url
}).then(success => {
// success callback
}).catch(error => {
// error call back
})
React version 16.8.6
and React Native version 0.60.4
is used.
React hooks are followed in the project.