aleph.js icon indicating copy to clipboard operation
aleph.js copied to clipboard

Support for using arrow functions for React Components

Open noverby opened this issue 4 years ago • 4 comments
trafficstars

The following code does not run:

import React from "react";
import { Button } from "https://esm.sh/@material-ui/core";

export default () => {
  return <Button>Test</Button>;
};

It results in the error:

400 - Module "Page Component: /pages/index.tsx" should export a React Component as default

noverby avatar Apr 13 '21 19:04 noverby

Currently our function to detect if a function is a React component doesn't support arrow functions. @ije Do you know any way it could be done?

shadowtime2000 avatar Apr 13 '21 19:04 shadowtime2000

Next.js uses isValidElementType from react-is to verify whether the objects, returned from either type of functions, are React components. Source

noverby avatar Apr 14 '21 08:04 noverby

i don't think so react-is can get this, in fact the isLikelyReactComponent function is copied from react repo, and the unnamed arrow function component also don't support fast-refresh. try to use const snytax:

const A = () =><Button>Test</Button>
export default A

ije avatar Apr 15 '21 18:04 ije

this should be handle in compiler

ije avatar Aug 24 '21 04:08 ije