Skip to content

Commit

Permalink
clarify execution order of init (#3702)
Browse files Browse the repository at this point in the history
there are multiple ways to run code on Alpine initialization, so this clarifies the order of execution of the object `init()` method vs the `x-init` directive.
  • Loading branch information
browner12 committed Aug 28, 2023
1 parent cb580d7 commit d77d117
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/docs/src/en/directives/init.md
Expand Up @@ -72,3 +72,18 @@ Alpine.data('dropdown', () => ({
},
}))
```

If you have both an `x-data` object containing an `init()` method and an `x-init` directive, the `x-data` method will be called before the directive.

```alpine
<div
x-data="{
init() {
console.log('I am called first')
}
}"
x-init="console.log('I am called second')"
>
...
</div>
```

0 comments on commit d77d117

Please sign in to comment.