-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update to use new React context #51
Comments
🤔 d3plus as a library is designed to run in the browser and the package is exported in ESM format. From some initial googling, I found the following StackOverflow post which says that NextJS will only compile ESM import/exports that are present in the |
Ehy @davelandry, thanks for the hint, I'll take a look at it. Meanwhile, as a temporary workaround, I managed to make it work copying the Now I've got React complaining about the usage of Legacy context API in the Hope I made myself clear, I'll post news ASAP |
UPDATE I tried to use So just const withTM = require('next-transpile-modules')(['d3plus-react']);
module.exports = withTM({
reactStrictMode: true
}); It works properly but I still get the Legacy context API warning from React. This makes sense because this module does exactly what I did manually and described in my previous post. This is the warning:
So I decided to stick with my solution and replace the legacy context with the new React Context API, so I've got a correct module load and no annoying React warning. @davelandry don't know if that's something that may be of interest to you, I just created and exported a context from export const D3PlusContext = React.createContext({
d3plus: {}
});
class Viz extends Component {
static contextType = D3PlusContext;
// ... everything as it was before
}
// removed this
// Viz.contextTypes = {
// d3plus: PropTypes.object
// }; An example of usage: import { D3PlusContext } from '../d3plus-wrapper';
/*
* this is where I put the wrapper, I guess the best solution would be to export it from `index.js`
* so you can just do - import { D3PlusContext } from 'd3plus-react' -
*/
// example of comfiguration I took from your README
const d3plusConfig = {
shapeConfig: {
fontFamily: "Comic Sans MS"
}
};
const MyApp = () => {
return (
<D3PlusContext.Provider value={{ d3plus: d3plusConfig }}>
<main>
{/* child components containing visualizations */}
</main>
</D3PlusContext.Provider>
);
};
export default MyApp; Thank you for your time |
@francescocretti I also ran into the same problem using d3plus + next.js. My solution has to wrap the d3plus component I was importing with a dynamic import like the following:
My
|
Thanks @alexandersimoes for the alternative! |
With version v1.2 of the library, we have upgraded the codebase to use proper imports/exports and are now exporting a Context/Provider to use when passing down global configs: https://github.com/d3plus/d3plus-react/releases/tag/v1.2.0 |
Hi everyone. Thanks for developing and maintaining this package.
I'm encountering a strange error when trying to use
d3plus-react
in a Next.js project.In particular I'm trying to use the
GeoMap
component.Expected Behavior
Install
d3plus-react
, importGeoMap
in custom component and use with custom data.Current Behavior
The mere fact of importing the
GeoMap
throws a build-time error:SyntaxError: Unexpected token 'export'
.Steps to Reproduce (for bugs)
d3plus-react
GeoMap
fromd3plus-react
Attachments
Here's a screenshot of the error
Here's my component's code
Your Environment
Let me know you I can provide any other information. Thanks a lot.
Francesco
The text was updated successfully, but these errors were encountered: