我得到一个TypeError:null不是一个对象(正在评估'dataSource.map')[重复]

问题描述 投票:-1回答:1

我收到此错误

TypeError:null不是一个对象(正在评估“ dataSource.map”)

我看过其他解决方案,但我不明白为什么setDatasource不会将dataSource从null更改。

import React, { Component, useState, useEffect } from "react";
    import { View, Text, StyleSheet, ActivityIndicator } from "react-native";
    import { ScreenContainer } from "react-native-screens";

    export const Home = () => {
      const [isLoading, setisLoading] = useState(true);
      const [dataSource, setdataSource] = useState(null);

      useEffect(() => {
        return fetch("https://facebook.github.io/react-native/movies.json")
          .then((response) => response.json())
          .then((responseJson) => {
            setisLoading(false), setdataSource(responseJson.movie);
          });

        // .catch((error)) => {
        //   console.log(error)
        // }
      });
      if (isLoading) {
        return (
          <View>
            <ActivityIndicator />
          </View>
        );
      } else {
        let moviest = dataSource.map((val, key) => {
          return (
            <View key={key}>
              <Text>{val.title}</Text>
            </View>
          );
        });

        return (
          <ScreenContainer style={styles.container}>
            <View>
              <Text>These are the movies</Text>
              {moviest}
            </View>
          </ScreenContainer>
        );
      }
    };
python python-3.x list variables
1个回答
1
投票
您可以将collections.Counterdoc)用于任务:
© www.soinside.com 2019 - 2024. All rights reserved.