Can carto-react with next application also?
sabit990928 opened this issue · 2 comments
Hey!
From the guide and doc I saw that it's work fine in CRA and even generates some files which needed, but is it works by the same principle in Next application?
Hi!
The library is not designed to work using server side rendering with Next.js.
Some functions make use of objects only available in the browser (like the window
object) so you will receive a ReferenceError: self is not defined
error when you import functionality from the packages.
To solve the import problem, one option is to use standard dynamic imports if you want to import functions (i.e. createCartoSlice) or variables (i.e. basemaps). If you want to import a React component (i.e. FormulaWidget), you can use the Next.js dynamic import functionality.
The library uses Redux Toolkit for state management, so you should wrap your App
component with your Redux store provider and create the corresponding slices as the Create React App templates do. You could also try using next-redux-wrapper.
Closing.