Vexor.init()
Static Initialization
There are 3 ways to instantiate a Vexor instance:
- Using the
new Vexor()
constructor with publishable key, project id and secret key. -
Using the
Vexor.init()
static method. - Using the
Vexor.fromEnv()
method to initialize the Vexor instance from environment variables.
The Vexor.init()
method provides a convenient way to create a new Vexor instance without using the new
keyword. It's particularly useful when you want to create an instance in a single line of code or when working with dependency injection systems.
This method internally calls the Vexor constructor with the provided parameters, creating and returning a new Vexor instance.
StaticVexor.init(params)
Vexor.init()
Initialize a new Vexor instance using a static method.
Parameters
Returns
Returns a new Vexor instance.
Recommendations
- Create a
.env
file in your project root and add your Vexor environment variables:
WARNING: Do not store any secrets (such as VEXOR_SECRET_KEY) in your React app! These keys should be handled on the server side.
- Create a
vexor.ts
file in yourlib
orutils
folder and export the Vexor instance:
Choose the method that best fits your application's architecture and security requirements.
The Vexor.init()
method is functionally equivalent to using the new Vexor()
constructor. It's provided as an alternative syntax that some developers may find more intuitive or easier to use in certain contexts.