ManuelDeLeon / viewmodel-react

Create your React components with view models.
MIT License
24 stars 3 forks source link

How do I make viewmodel-react work with Next.js? #51

Open fvpDev opened 4 years ago

fvpDev commented 4 years ago

How do I make viewmodel-react work together with Next.js? I worked with ViewModel on Meteor a few years back but now wish to try something new.

I was able to adjust my package.json according to https://nextjs.org/docs/advanced-features/customizing-babel-config to:

  "babel": {
    "presets": [
      "next/babel"
    ],
    "plugins": [
      "module:viewmodel-react-plugin"
    ]
  }

however now I am getting an error that React is already declared:

[ error ] ./pages/components/person.js 21:7
Module parse failed: Identifier 'React' has already been declared (21:7)
File was processed with these loaders:
 * ./node_modules/next/dist/build/webpack/loaders/next-babel-loader.js
You may need an additional loader to handle the result of these loaders.
|
| import ViewModel from "viewmodel-react";
> import React from "react";
| var VmLazyL;
| export var Person = /*#__PURE__*/function (_React$Component) {

The next/babel presets already include: preset-env (which I understand is es2015) preset-react (which I understand is react)

ManuelDeLeon commented 4 years ago

I couldn't get VM to work with Next.js =/ I was able to use hooks to get a similar experience. Here's an example: https://github.com/ManuelDeLeon/react-props-example

fvpDev commented 4 years ago

Thanks man, I'll check it out. The quick response is much appreciated! I'm still kinda learning Next.js as well.