Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

Typescript: property "title" does not exist on type 'never'

$
0
0

I am practicing React-native typescript. I fetched the data from jsonplaceholer API and added to my component state. After mapping the state and try to render on my mobile. But I am getting typescript error on my terminal: property "title" does not exist on type 'never'.

This is my app component

import React, { useState, useEffect } from "react";import { StyleSheet, Text, View, ScrollView, Image } from "react-native";export default function App() {  const [state, setstate] = useState([]);  useEffect(() => {    fetchData();  }, []);  const fetchData = async () => {    const response = await fetch("https://jsonplaceholder.typicode.com/photos");    const data = await response.json();    setstate(data);  };  return (<ScrollView style={styles.body}><View style={styles.container}>        {state.map(list => {          return <Text>{list.title}</Text>; //        })}</View></ScrollView>  );}const styles = StyleSheet.create({  body: {    padding: 150  },  container: {    flex: 1,    backgroundColor: "white",    alignItems: "center",    justifyContent: "center"  },  stretch: {    width: 50,    height: 200,    resizeMode: "stretch"  }});

Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>