question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initialize a plugin inside a React component

See original GitHub issue

What is the current behavior? I’m trying to initialize a plugin inside a React component to have access to the application data.

Please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox.io or similar. All the comments are inside the TinyMCE file component: https://codesandbox.io/s/tinymce-erssm

What is the expected behavior? To initialize the plugin inside the component, for example, inside an effect and not just outside the component which is not possible to access the application data.

Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or tinymce-react? tinymcereact - 3.3.2
tinymce - 5.1.1

I’ve never tried to do this in other versions.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SimonFccommented, Dec 5, 2019

Yeah at that point in time the TinyMCE global doesn’t exist since it’s being fetched and initialized from the cdn once the tinymce-react component initializes, not before. In such cases you can do something like this (note - perhaps make it so that the function that adds the plugin only gets run once in your apps life cycle for performance)

An alternative, if you prefer your current style, is to load TinyMCE manually from the cdn before your functional component initializes. Either by including the a script tag as described here or perhaps even do it programmatically as we’re doing here.

Hope this helps!

0reactions
mikedlosscommented, Dec 4, 2019

@SimonFc that sounds all like where my mind was leading me yesterday 😬Yeah we aren’t self hosting, honestly all I’ve done so far was just install @tinymce/tinymce-react into my project and am just using it inside of a functional component. I was trying to create / initialize the plugin above the rendered component (so hoisted above what React is handling), and was looking at window.tinymce to do what I want. I keep finding that that tinymce object exists, it’s just I kept getting that error.

More specifically, I was using that tinymce code snippet inside of this code block:

import { Editor as TinyMCE } from '@tinymce/tinymce-react';

if (window && window.tinymce) {
  const { tinymce } = window;
  tinymce.PluginManager.add('example', (editor, url) => ...more code goes here);
}

// ...later in the same file
// props includes the init object with the plugin list, including the `example` plugin
 
const Editor = (props) => {
  return (
    <TinyMCE apiKey="api-key" init={{ plugins: ['example', ...more plugins], ...more init}} {...props} />
  )
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating with Other Libraries - React
To demonstrate this, let's sketch out a wrapper for a generic jQuery plugin. We will attach a ref to the root DOM element....
Read more >
React - initialize a plugin inside a component (didMount?)
I would do initialization of plugins in componentDidMount and componentDidUpdate if the element that the plugin applies to changes.
Read more >
How to Use ReactJS Components as jQuery Plugins
In order to transform our React component into a jQuery plugin, we need to do two things. First, we obviously need to create...
Read more >
React Plugin - LogRocket Docs
The LogRocket React plugin allows you to filter for sessions where the user clicks a specific component in your React app. The npm...
Read more >
Building Plugins for React Apps - Nylas
Plugin components need to appear somewhere in the application, but other components don't know how to render them. Adding them directly to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found