react-native-dva
React Native Dva for Android and iOS
Getting started
$ npm i @lighthouseapps/react-native-dva --save
Usage
// ./src/models/app.js
export default {
namespace: 'app',
state: {},
effects: {},
reducers: {},
subscriptions: {}
};
// ./src/models/index.js
import app from './app';
export default [
app
];
// ./src/router.js
import {
LoadingScreen,
SigninScreen,
HomeScreen
} from './screens';
import {
AppLayout
} from './layouts';
export default {
type: 'switch',
routes: [
{
type: 'screen',
name: 'Loading',
layout: null,
component: LoadingScreen
},
{
type: 'screen',
name: 'Signin',
layout: null,
component: SigninScreen
},
{
type: 'stack',
name: 'App',
layout: null,
routes: [
{
type: 'screen',
name: 'Books',
layout: null,
component: HomeScreen
}
],
options: {}
}
],
layout: AppLayout,
options: {}
}
// index.js
import React from 'react';
import dva, {
createRouter
} from 'react-native-dva';
import App from './App';
import models from './src/models';
import router from './src/router';
import {
name
} from './app.json';
const {
routerMiddleware,
routerReducer,
Router
} = createRouter(router);
const app = dva({
models,
extraReducers: { router: routerReducer },
onAction: [ routerMiddleware ]
});
app.start(name, <Router />);