How balaji-sb/rtk-query-with-react-native works
Project type and purpose
• This is a React Native mobile application (iOS & Android) using Redux Toolkit Query for data fetching.
• Purpose: display and manage a Todo list via a remote REST API.
File structure
• Top-level “android” and “ios” folders: native platform projects with Gradle and Xcode configurations.
• “App.tsx” & “index.js”: entry point into the JavaScript app.
• “src/” contains all JS/TS code, divided into:
• “ui/” – React components (TodoListUi)
• “redux/” – store setup, RTK logger, provider wrappers
• “services/” – API definitions (TodoApi, api.ts), service constants
• “model/” – TypeScript types for API responses
• “hooks/” – custom selectors
• Config files: babel.config.js, metro.config.js, jest.config.js, tsconfig.json.
README for additional insights
• Bootstrapped with React Native CLI.
• Standard Metro bundler → JavaScript bundle → native runtime.
• No custom backend: the app consumes external Todo API endpoints via RTK Query.
Main components
a. Mobile device (iOS Simulator / Android Emulator / Physical Device)
b. Metro Bundler & Packager (development only)
c. JavaScript runtime & React Native Bridge
d. React components (UI layer)
e. Redux store & middleware (RTK Logger)
f. RTK Query “Api slice” service layer (TodoApi + baseApi)
g. Network layer (fetch/XHR)
h. External REST API (TodoList service)
i. Native modules (Android / iOS code for device capabilities)
Relationships and interactions
• On app launch, Metro serves the bundle → JS runtime loaded onto device → React Native Bridge initializes native modules.
• UI components dispatch Redux actions or RTK Query hooks.
• Redux store updates state; RTK Query middleware intercepts data-fetching actions.
• RTK Query issues network requests to External API.
• Responses flow back through RTK Query → Redux store → trigger UI re-render.
• Native modules invoked indirectly by React Native Bridge for device-specific features (if any).
Architectural patterns & design principles
• Unidirectional data flow (React → Redux → RTK Query → API → Redux → React).
• Separation of concerns:
• UI layer (stateless components)
• State management layer (Redux store + middleware)
• Data fetching layer (RTK Query slices)
• Networking layer (fetch wrapper in services)
• Strong typing via TypeScript models for API contracts.
Relevant technologies/frameworks
• React Native (JS UI + Native Bridge)
• Redux Toolkit (store.ts, ProviderList, StoreProvider)
• RTK Query (TodoApi, api.ts)
• TypeScript (tsconfig.json, *.ts/.tsx)
• Metro bundler (metro.config.js)
• Native toolchains (Gradle for Android, Xcode for iOS)
Elements
• User → UI → Redux Dispatch
• Redux → RTK Query → Network → API
• API → RTK Query → Redux → UI
• Orange cloud for External API
• Gray for development tools (Metro)
Detailed layer breakdown (suggested grouping)
[User Device]
└── React Native Bridge
├── UI Layer (src/ui/*.tsx)
├── State Layer (src/redux/*.tsx, store.ts)
│ └── RTK Logger middleware
├── Data Layer (src/services/api.ts, TodoApi.ts)
│ └── ServiceConstants.ts
└── Models & Hooks (src/model, src/hooks)
[Network]
↔ fetch / axios wrapper
[External]
└── Todo REST API