I'm new in react-native I've been trying to fetch data from an API and then show them in a view. this is my code
FetchSignatures.js :
const URL = 'http://localhost:8000';
export default {
async fetchSignatures() {
try{
let response = await fetch(URL+'/api/signatures');
let responseJsonData = await response.json();
return responseJsonData;
}
catch(e){
console.log(e)
}
}
}
Signatures.js :
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import ajax from '../services/FetchSignatures';
import SignaturesList from '../components/SignaturesList';
export class Signatures extends Component {
state = {
signatures: []
}
async componentDidMount() {
const signatures = await ajax.fetchSignatures();
this.setState({signatures});
}
render() {
return (
<View>
{
this.state.signatures.length > 0 ? <SignaturesList signatures=
{this.state.signatures}/> : <Text>No Guest</Text>
}
</View>
)
}
}
export default Signatures;
It always return an erro that said "TypeError: Undefined is not an object (evaluating 'this.state.signatures.length').
this is my API's screen shoot :
Please Somebody Help me to Solve this.. Thank's in advance..
