因此,我尝试通过以下查询从Firestore中获取数据:
class AttendanceDuration extends React.Component {
render () {
const {attendances} = this.props; // received from mapStateToProps
const {index_of_tab} = this.props; // received from Parent Component
return (
//JSX Rendering
)
}
}
const mapStateToProps = (state) => {
const dbReceived = state.firestore && state.firestore.data.StudentScanClass;
const attendances = dbReceived ? state.firestore.ordered.StudentScanClass : [];
return {
attendances: attendances,
}
}
export default compose(
connect(mapStateToProps),
firestoreConnect( props =>
{
const {single_class, index_of_tab, index_of_pill} = props; // Received from Parent and Changing based on selected tab's index
console.log(props)
if(index_of_pill == 0) {
return [
{
collection : 'StudentScanClass',
where: [
['unitcode', '==', props.single_class.unitcode],
['course', '==', props.single_class.courses[index_of_tab].course],
["date", ">", begin_date_weekly],
["date", "<", end_date_weekly],
['yearofstudy', '==', props.single_class.courses[index_of_tab].yearofstudy.toString()],
],
}
]
} else if (index_of_pill == 1) {
return [
{
collection : 'StudentScanClass',
where: [
['unitcode', '==', props.single_class.unitcode],
['course', '==', props.single_class.courses[index_of_tab].course],
["date", ">=", begin_date_weekly],
["date", "<=", end_date_weekly],
['yearofstudy', '==', props.single_class.courses[index_of_tab].yearofstudy.toString()],
],
}
]
}
}
)
) (AttendanceDuration);
因此,基本上我是从父组件加载此组件的,其中父index_of_pill
会根据所选选项卡而变化。问题是当我选择其他选项卡,然后转到上一个选项卡时, attendances
数据不会相应更新。 “卡住了” 。
我该如何解决?