I assume you are using the Moralis React Boilerplate.
If you want to use Moralis independent of React, you need to do 2 things:
-
import Moralis from "moralis";
in the file where you have
const OrdersList = Moralis.Object.extend('OrdersList');
-
Initialize Moralis with your server info as documented here, under the section Initialize the SDK.
This would be your solution if you intend to use the Orders()
function outside of the React App. Probably not the case.
You probably want to use Orders()
inside of the React App.
So here is the best solution, IMO;
Use Moralis hooks.
You have a Moralis object that is initialized and accessible within the <MoralisProvider>
in index.js.
This Moralis object is the one you get when you call the useMoralis()
hook.
If you can do
const {Moralis} = useMoralis();
const OrdersList = Moralis.Object.extend('OrdersList');
then that’s your solution.
If this solution fails to build, read on:
There is a chance you can’t do this in your .js file code.
e.g. because that code is outside of a React component or a React Hook, like in a file with helper functions.
In this case, I assume that the Orders()
function is still eventually used in a React component or hook.Then you can get your “React”-Moralis Object from there and pass it into your function:
const Orders = async (Moralis) =>{
const OrdersList = Moralis.Object.extend('OrdersList');
const orderz = new OrdersList ();
}