Is it possible to make a fetch
request normally to teh database without using the Moralis.query
or useMoralisQuery
You can call a cloud function with rest and a cloud function can make that query.
How exactly would I do this syntactically
What part you donโt know how to do?
What Iโm trying to do is dynamically render pages with NextJS using the getStaticPaths function.
My code looks something like this
export const getStaticPaths = async () => {
const { data: AllMails, error, isLoading } = useMoralisQuery("AllMails");
const paths = AllMails.map((mail) => {
return {
params: { id: mail.attributes.mailID },
};
});
return {
paths,
fallback: false,
};
};
Now for some reason Iโm getting a TypeError: Cannot read properties of null (reading 'useContext')
pointing at the useMoralisQuery hook. I have no idea why this is happening but i do know that making normal fetch requests work as expected.
Thats why i asked if there was a way to make a regular fetch request straight to my moralis DB and get all the information i need.
Id appreciate the feedback!!
Does Moralis.Query not work? Another option is to set up a cloud function that queries the data, and then you can call that cloud function over REST API.
You can only use hooks like useMoralisQuery
inside function components (or other hooks), that is why youโre getting that error.
Moralis.Query should work, but the problem is getting Moralis into the function to work. Iโd try out the cloud function now and give a feedback