DEV Community

Cover image for Dativejs Tutorial - Creating a Dative instance
Tobi
Tobi

Posted on

Dativejs Tutorial - Creating a Dative instance

Creating A Dativejs Instance

In Dative 2-alpha there are two ways of creating an instance for your application

  1. new Dative
  2. defineApp

The new Dative is the normal way we know in the v1-v2 but the defineApp is the new way which also uses the same options api like new Dative but with the defineApp you don't need to use the new keyword

Let's start cooking 🥳🍜

defineApp<T extends DativeOptions>(options: T): Dative
Enter fullscreen mode Exit fullscreen mode
import { defineApp } from 'dativejs'

let app = defineApp({
   data: ()=>({
      message: "Holla"
   }),
   template: `
     <div>
       <h1>{{message}}</h1>
     </div>
   `
})
Enter fullscreen mode Exit fullscreen mode

Notice That there's not app.render() again like the v1-v2

The v2-alpha render automatically when there's an el options or when you use the app.mount(el: string)

New options has been added to the instance
Check API docs

Next blog will be on the {{#if}} block

Thanks for reading ❤️❤️

Top comments (0)