react usual

196 阅读1分钟
import React from 'react';
import { StyleSheet, ImageBackground, Text, View } from 'react-native';

import UI from '~/modules/UI';
import MyTouchable from '~/components/my-touchable';
import NavigationHeader from '~/components/navigation-header-hook';
import { dispatch } from '~/modules/redux-app-config';


function WordBank() {
  return (
    <View style={styles.container}></View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  }
});

export default WordBank

models/rating-test.js

export const ratingTest = {
  default: {
    questions: [],
  },
  persist: true,
  actions: {
    UPDATE_RATING_TEST: {
      reducer: (state, { payload }) => ({
        ...state,
        ...payload,
      }),
    },
  },
};

api/plan.js

/** 学习计划相关接口 */
import Config from 'react-native-config';
import request from '~/modules/services/request';
import { store } from '~/modules/redux-app-config';
import { getHeader, filterUrl } from '~/modules/services/utils';

const { API_URL } = Config;

/**
 * @description 获取定级测试题目列表
 */
async function getRatingTest(query) {
  const url = filterUrl(query);
  return request(`/learning/plan/questions${url}`, {
    method: 'GET',
    headers: getHeader(store),
  });
}

module.exports = {
  getRatingTest,
};

saga.js


// 定级测试列表
export function* getRatingTest(actions) {
  const { payload = {} } = actions;
  const res = yield call(api.getRatingTest, payload);
  if (res && res.msg === 'success') {
    const { data } = res;
    const { questions } = data;
    yield call('UPDATE_RATING_TEST', { questions });
  }
  payload.res && payload.res(res);
}

 takeEvery('GET_RATING_TEST', getRatingTest),