Open garronej opened 1 year ago
In this particular case, shouldn't it be
"use client";
export function createMyComponent() {
function MyComponent() {
return <h1>Hello World</h1>;
}
return <MyComponent />;
}
?
This way it would be an actual component being returned, right?
Hello @TillHeinzel,
No this isn't the usecase.
"use client";
export function createMyComponent() {
function MyComponent() {
return <h1>Hello World</h1>;
}
return { MyComponent };
}
is to be used like:
// app/pages.tsx
import React from "react";
import { createMyComponent } from "../shared/MyComponent";
const { MyComponent } = createMyComponent();
function DefaultPage() {
return (
<>
<MyComponent />
</>
);
}
export default DefaultPage;
seconded, but note it is only erroring with client components
I second this issue as I already mentioned this problem in an other issue #44030 about compound components.
seconded, but note it is only erroring with client components
My UI components are usually the one I want to "compose" but also the ones that require to be in "use client" files... Thus I encounter this problem frequently.
Hello next pepoles :)
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/garronej/mui-next-appdir-demo/tree/higher_order_function_component
To Reproduce
Describe the Bug
Can't use higher order functions that returns components like:
We get:
Expected Behavior
I would expect it to work as it makes it impossible to make existing API compatible with AppDir without introducing breaking changes.
Thank you for your work!
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response