Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Components with hooks fail phenomic build process #1275

Closed
Jokinen opened this issue Mar 14, 2019 · 2 comments
Closed

Components with hooks fail phenomic build process #1275

Jokinen opened this issue Mar 14, 2019 · 2 comments

Comments

@Jokinen
Copy link
Contributor

Jokinen commented Mar 14, 2019

This can be reproduced in the react-app-minimal-hello-world example by upgrading react into version 16.8.0 and using hooks:

// @flow

import React, { useState } from "react";
import { Router, Route, browserHistory } from "react-router";
import { createApp } from "@phenomic/preset-react-app/lib/client";
// import { createApp, renderApp } from "@phenomic/preset-react-app/lib/client";

const Example = () => {
  const [test, setTest] = useState(false)

  return 'Hello world'
}

export default createApp(() => (
  <Router history={browserHistory}>
    <Route path="/" component={Example} />
  </Router>
));

// uncommment to get hot loading
// if (module.hot) {
//   module.hot.accept(() => renderApp(routes));
// }

The error message redirects you here https://reactjs.org/warnings/invalid-hook-call-warning.html

phenomic start works fine, so I was caught a bit off guard, but I guess phenomic does a bit of magic when building so it's not completely odd. Any idea on when hooks become usable?

Using latest version from next.

@MoOx MoOx closed this as completed in cccee0e Mar 15, 2019
@MoOx
Copy link
Owner

MoOx commented Mar 15, 2019

Thanks for reporting.
This was due to SSR that were using 2 versions of the same react (one compiled in webpack bundle, one not...). I fixed it by adding react & react-dom as external deps for static rendering.

So Hooks should work with latest beta (10). Enjoy!

@Jokinen
Copy link
Contributor Author

Jokinen commented Mar 15, 2019

Thanks for the explanation and quick fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants