Как отобразить данные через Sectionlist после получения их из пожарного магазина - PullRequest
0 голосов
/ 16 января 2019

Я хочу получить данные из облачного пожарного хранилища и поместить данные в SectionList. Я могу показать это через Flatlist. Я получу TypeError: undefined не является объектом (оценка 'section.data.length')

Я пытался поместить Todo в отдельный класс, но я не могу показать вывод

export default class Todos extends Component {
constructor() {
    super();
    this.ref = firebase.firestore().collection('boards');
    this.unsubscribe = null;
    this.state = {
        textInput: '',
        loading: true,
        boards: [],
    };
}
componentDidMount() {
    this.unsubscribe = this.ref.onSnapshot(this.onCollectionUpdate) 
}

componentWillUnmount() {
    this.unsubscribe();
}
onCollectionUpdate = (querySnapshot) => {
    const boards = [];
    querySnapshot.forEach((doc) => {
      const { emotion } = doc.data();
      boards.push({
        key: doc.id,
        doc, // DocumentSnapshot
        emotion,
      });
    });
    this.setState({ 
      boards,
      loading: false,
   });
  }

 render() {
if (this.state.loading) {
    return null; // or render a loading icon
}
return (
    <View style={{ flex: 1 }}>

    <SectionList

                renderSectionHeader={({ item,index }) => {
                    return (<Todo item={item} index={index} />);
                }}
                sections={this.state.boards}
                keyExtractor={(item, index) => index}>
            </SectionList>
</View>
);
}

}

class Todo extends Component {
render() {
    return (

          <View style={{ flex: 1, height: 48, flexDirection: 'row', alignItems: 'center' }}>
              <View style={{ flex: 8 }}>
                  <Text>{this.props.item.motion}</Text>
              </View>
          </View>

    );
}
}

Я ожидаю увидеть данные, которые я написал, какие радости, любви и т. Д.

...