Replace require with import in MarkdownEditor's FormattingTools component
#2334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
FormattingToolscomponent (owned byMarkdownEditor) depends on themarkdown-toolbar-element. This library performs DOM-based side-effects on render, so it cannot be imported at the top level of the file - it must be imported in an effect.I originally tried to use
import()inside auseEffectfor this but ran into problems so I usedrequire()instead. Now, we've started running into problems with the mix ofrequireandimportin a file and I'd like to revisit trying to useimport.It seems to be working fine so far - Storybook, Gatsby docs, and tests all build alright. I think that the issue I was running into before was likely not due to the use of
importbut rather that I had forgotten toawaittheimportbecause I didn't realize that it was aynchronous. If that is the case, then it should be fine to switch the strategy and I think it will solve a lot of complications.