Skip to content

AK0012

inject() called outside of component setup

What happened

You called inject() outside of a defineComponent() setup function. AkashJS requires an active component context to look up injected values.

How to fix

Move the inject() call inside defineComponent()'s setup function.

Example

ts
// Bad
import { inject } from "akashjs";

const theme = inject("theme"); // not inside defineComponent!

// Good
import { defineComponent, inject } from "akashjs";

const MyComponent = defineComponent(() => {
  const theme = inject("theme");

  return () => h("div", { class: theme.mode });
});

Released under the MIT License.