ryanseddon / react-frame-component

Render your React app to an iFrame
http://ryanseddon.github.io/react-frame-component/
MIT License
1.75k stars 156 forks source link

Error in Remix app #252

Closed jsgv closed 9 months ago

jsgv commented 9 months ago

I am unable to get it to work on a Remix app. I get the following error message:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Code:

import Frame from "react-frame-component";

export default function Index() {
  return (
    <div>
      <p>Hello</p>
      <Frame>
        <h1>Testing</h1>
      </Frame>
    </div>
  );
}

Sandbox Link: https://codesandbox.io/p/devbox/crimson-night-pydmg6?file=%2Fapp%2Froutes%2F_index.tsx

jsgv commented 9 months ago

So it looks like the importing of the library is weird. The Frame component I need is the default field.

import Frame from "react-frame-component";

export default function Index() {
    console.log(Frame);

    return (
        <div>
            <p>Hello</p>
            <Frame.default>
                <h1>Testing</h1>
            </Frame.default>
        </div>
    );
}

Console

image

ryanseddon commented 9 months ago

So I think this is something weird Remix is doing with modules that have a default export. As even if I try and do:

import { default as Frame } from 'react-frame-component';

Logging out Frame still returns all the exports?

I even tried a different component that also default exports and it's the same error? https://codesandbox.io/p/devbox/determined-cherry-srvpy3?file=/app/routes/_index.tsx:9,19

I'd reach out to remix and see what their compiler is doing to default export modules in routes.

jsgv commented 9 months ago

It seems you are correct about Remix doing something weird with default imports. I guess I will have to check with them. Thanks for the reply @ryanseddon