Skip to content
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

Does this support React.lazy component #128

Open
edwards-afterpay opened this issue Feb 8, 2021 · 1 comment
Open

Does this support React.lazy component #128

edwards-afterpay opened this issue Feb 8, 2021 · 1 comment

Comments

@edwards-afterpay
Copy link

edwards-afterpay commented Feb 8, 2021

Below code doesn't work as I expected. Have been running into

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <ErrorBoundary />. Did you accidentally export a JSX literal instead of a component?

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

React lazy component

const ProfileLazy = React.lazy(() => import("./Profile"));

const Profile =
    <ErrorBoundary>
    <Suspense fallback={<div>Loading...</div>}>
        <ProfileLazy />
    </Suspense>
</ErrorBoundary>

Angular react2angular wrapper

angular.module("application.module.profile", [])
.controller("application.module.profile.controller",
        ["$rootScope", "$scope", "$controller"],
        function ($rootScope, $scope, $controller) {
            $controller("application.module.controller", {$scope: $scope});
        })
    .component('profile', react2angular(Profile, [], []))

Can I clarify if react2angular will work with the dynamic imports in general, or if there is any issue with the code snippet I have written? Keen to hear your thoughts to understand how can we make this work.

@RusmiselE-lattice
Copy link

@edwards-afterpay This isn't a problem with react2angular. To quote the error: "React.createElement: type is invalid...Did you accidentally export a JSX literal instead of a component?"

The problem is that Profile isn't a component here but a JSX literal. To fix your error, you can just make it a function:

const Profile = () => (
    <ErrorBoundary>
        <Suspense fallback={<div>Loading...</div>}>
            <ProfileLazy />
        </Suspense>
    </ErrorBoundary>
);

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

No branches or pull requests

2 participants