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

Apllo Server (Query Data)

$
0
0

I need help with this code I'm trying to get the data from database mangodb using abolloserver, but I'm not getting anydata, and when I'm trying to console.log(data) I'm getting undefind,

The query is working normal from the apllo client interface but it dons't work with react native.

import { StyleSheet, FlatList, Alert } from 'react-native';import EditScreenInfo from '../components/EditScreenInfo';import { Text, View } from '../components/Themed';import { useState, useEffect } from 'react';import { useQuery, gql } from '@apollo/client';import ProjectItem from '../components/ProjectItem/Index';const MY_PROJECTS = gql`  query myTaskLists {    myTaskLists {      id      title      createdAt    }  }`export default function ProjectsScreen() {  const [project, setProjects] = useState([]);  const { data, error, loading } = useQuery(MY_PROJECTS);  console.log(data);  useEffect(() => {    if (error) {      Alert.alert('Error fetching projects', error.message);    }  }, [error])  useEffect(() => {    if (data) {      setProjects(data.myTaskLists);    }  }, [data])  return (<View style={styles.container}>      {/* Project/Task List */}<FlatList        data={project}        renderItem={({item}) => <ProjectItem project={item} />}        style={{ width: '100%' }}      /></View>  );}const styles = StyleSheet.create({  container: {    flex: 1,    alignItems: 'center',    justifyContent: 'center',  },});

Viewing all articles
Browse latest Browse all 6287

Trending Articles