Skip to content

force state to trigger update.Β #14182

@Celestialme

Description

@Celestialme

Describe the problem

For example usign Tip-Tap editor
`<script>
import { onMount, onDestroy } from 'svelte';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';

let element;
let editor;

onMount(() => {
	editor = new Editor({
		element: element,
		extensions: [StarterKit],
		content: '<p>Hello World! 🌍️ </p>',
		onTransaction: () => {
			// force re-render so `editor.isActive` works as expected
                           editor = editor
		},
	});
});

onDestroy(() => {
	if (editor) {
		editor.destroy();
	}
});

</script>`

editor = editor;
this no longer does anything.
if anyone is in the same boat my current approach is

let editor = $state<() => Editor>();
onMount(() => {
		let _editor = new Editor({
			element: element,
			extensions: [StarterKit],
			content: '<p>Hello World! 🌍️ </p>',
			onTransaction: () => {
				// force re-render so `editor.isActive` works as expected
				 let _editor = editor();
				 editor = ()=>_editor;
			},
		});
             editor = () => _editor;
	});

Describe the proposed solution

trigger(editor)
so it calls update on everywhere where it is used. on DOM, $derived,$effect and so on.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions