I am writing a little react app and I am trying to get data from a graphql server. I think (big emphisis on the word think) I am querying it correctly however it compiles but then gives me the following error message:
TypeError: Object(...) is not a function
It refers to line 16 which is where I define the Users function.
After a bit of googling a came across this: TypeError: Object(...) is not a function reactjs Whereby they seem to point to the person not importing/exporting there function correctly. However I do not believe I am doing that wrong. Any help or pointing in the right direction would be wonderful.
Thank you for reading and stay safe :)
code snippets:
Users file:
import React from "react";
import { useQuery } from "react-apollo";
import { gql } from "graphql-tag";
const QUERY_ALL_USERS = gql`
query getUsers {
users{
name
role
createdAt
}
}
`;
export const Users = () => {
const { loading, error, data } = useQuery(QUERY_ALL_USERS);
if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`;
const users = data.users.map((u) => {
return (
<li>
{u.name} <strong>{u.role}</strong>
</li>
)
})
return (
<ul>
{ users }
</ul>
);
};
App.js:
import { Users } from "./Users";
.
.
.
class App extends Component {
render() {
return (
<div className="app">
<header>
.
.
.
</header>
<Users />
</div>
);
}
}