Jungwoo-An / react-editor-js

⚛️📝The unofficial editor-js component for React
https://codesandbox.io/s/react-editor-js-v2-34bfl
MIT License
954 stars 77 forks source link

Not reloading with BrowserRouter #146

Closed PurplePineapple123 closed 3 years ago

PurplePineapple123 commented 3 years ago

I've run into an issue when using react-router. I have a navigation menu with routes to different pages each with their own editor js instance. When clicking a link in the menu, the URL changes, however, the editor does not load. The editor will only load correctly on a hard refresh of the page.

To isolate the issue, I removed the editor.js component and called a div showing the current page id. This div updated every time with the current URL id. However, adding back editor.js caused the issue to resume.

Any idea how to get editor.js to load when using react-router?

PurplePineapple123 commented 3 years ago

This is not an issue with editor.js, rather it has to do with the functionaility of react router.

If the same component is used as the child of multiple <Route>s at the same point in the component tree, React will see this as the same component instance and the component’s state will be preserved between route changes. If this isn’t desired, a unique key prop added to each route component will cause React to recreate the component instance when the route changes. Adding a unique key solved this issue :)