Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get an instance of editor with useEditor() in Nuxt 3 #30

Open
ynechaev opened this issue Dec 24, 2023 · 2 comments
Open

Can't get an instance of editor with useEditor() in Nuxt 3 #30

ynechaev opened this issue Dec 24, 2023 · 2 comments

Comments

@ynechaev
Copy link

ynechaev commented Dec 24, 2023

I am exposing lexical-vue with the following plugin:

// plugins/lexical.client.ts

import {
  useEditor,
  LexicalComposer,
  LexicalContentEditable,
  LexicalPlainTextPlugin,
} from 'lexical-vue'

export default defineNuxtPlugin(nuxtApp => {

  nuxtApp.vueApp.component('LexicalComposer', LexicalComposer)
  nuxtApp.vueApp.component('LexicalContentEditable', LexicalContentEditable)
  nuxtApp.vueApp.component('LexicalPlainTextPlugin', LexicalPlainTextPlugin)

  return {
    provide: {
      useEditor,
    }
  }

})

So inside the component when I try using it as following:

<template>
    <ClientOnly>
      <LexicalComposer :initial-config="config">
        <LexicalPlainTextPlugin>
          <template #contentEditable>
            <LexicalContentEditable />
          </template>
          <template #placeholder>
            <div>
              What do you want to write about today?
            </div>
          </template>
        </LexicalPlainTextPlugin>
      </LexicalComposer>
  </ClientOnly>
</template>

<script setup>
const {
  $useEditor: useEditor,
} = useNuxtApp()

const config = {
  editable: true,
  theme: { },
  onError(error) {
    console.error(error)
  },
}

const editor = useEditor()

// Two-way binding
const content = ref('')

</script>

I get an error: useEditor is not a function and trace shows <LexicalComposer /> is required error message (which is a bit misleading, because it throws when editor in underlying function is null

@yohames
Copy link

yohames commented Mar 26, 2024

Have you figured out a way to implement it in Nuxt 3?

@jswhisperer
Copy link

probably add .client.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants