我不确定导致错误的原因或解决方法。错误似乎表明它来自StudentHome组件,更具体地来说是Calendar组件。下面是StudentHome和Calendar组件,后面是错误的屏幕截图。 在此先感谢您的帮助。
StudentHome组件
import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import Calendar from './Calendar';
import StudentToolbar from './StudentToolbar';
import { MainContainer } from './common';
const navigationOptions = {
drawerLabel: 'Home',
drawerIcon: ({ tintColor }) =>
<Icon name="event-note" size={24} color={tintColor} />,
};
const StudentHome = MainContainer(props => {
return (
<View style={{ flex: 1 }}>
<StudentToolbar navigation={props.navigation} />
<View style={{ flex: 1 }}>
<Calendar />
</View>
</View>
);
});
StudentHome.navigationOptions = navigationOptions;
export default StudentHome;
以下是日历组件
import { Effects, loop } from 'redux-loop';
import { NavigationActions } from 'react-navigation';
import R from 'ramda';
import CalendarHelpers from '../helpers/calendars';
import {
LOAD_USER,
LOAD_CALENDARS,
LOAD_CALENDAR_EVENTS,
CREATE_USER_EVENT,
successActionType,
failActionType,
} from '../actions/types';
import {
apipost,
showSplashLoading,
hideSplashLoading,
showFlashMessage,
} from '../actions';
import reducer from './builder';
const INITIAL_STATE = {
items: {},
error: '',
creating: false,
};
const handlers = {
[successActionType(LOAD_USER)]: (state, action) => ({
...state,
items: action.payload.included['user-events'],
}),
[successActionType(LOAD_CALENDARS)]: (state, action) => {
if (!(action.payload.included && action.payload.included['user-events'])) {
return state;
}
return {
...state,
items: { ...action.payload.included['user-events'] },
};
},
[successActionType(LOAD_CALENDAR_EVENTS)]: (state, action) => {
const userEvents = R.pipe(
CalendarHelpers.getUserEventsResponse,
R.pluck('items'),
R.mergeAll
)(action.payload);
if (R.isEmpty(userEvents)) {
return state;
}
return {
...state,
items: { ...state.items, ...userEvents },
};
},
[CREATE_USER_EVENT]: (state, action) => {
const { resource, body } = action.payload;
return loop(
{ ...state, creating: true, error: null },
Effects.batch([
Effects.constant(showSplashLoading()),
Effects.constant(
apipost(
resource,
body,
{},
successActionType(CREATE_USER_EVENT),
failActionType(CREATE_USER_EVENT)
)
),
])
);
},
[successActionType(CREATE_USER_EVENT)]: (state, action) => {
//console.warn("Printing the state");//Just the state
//console.warn(state);
console.warn("Printing items in state");
console.warn(state.items);
const event = action.payload.data;
return loop(
{
...state,
creating: false,
items: { ...state.items, [event.id]: event },
},
Effects.batch([
Effects.constant(hideSplashLoading()),
])
);
},
[failActionType(CREATE_USER_EVENT)]: (state, action) =>
loop(
{ ...state, creating: false, error: action.payload },
Effects.batch([
Effects.constant(hideSplashLoading()),
Effects.constant(showFlashMessage(action.payload)),
])
),
};
export default reducer(handlers, INITIAL_STATE);