-
Notifications
You must be signed in to change notification settings - Fork 852
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
What are the plans for asChild and Slot with React.cloneElement be considered a legacy API method? #2537
Comments
I think you're mixing up "legacy" with "deprecated". One does not imply another and I see no information about cloneElement being deprecated. Do you have any source that actually claims that it is deprecated? I tried quick Googling with no luck. |
Hello. Indeed, deprecated and legacy are different, but Legacy API are recommended to be avoided for any new code, which eventually will become discontinued. "Legacy React APIs So.. I still think the issue is valid to ask for the team if there are plans. Reference: https://react.dev/reference/react/legacy |
const CollapsibleDemo = () => {
return (
<Collapsible.Root className="CollapsibleRoot">
<Collapsible.Trigger>
{(getProps, context) => (
<button {...getProps({ className: "IconButton" })}>
{context.open ? <Cross2Icon /> : <RowSpacingIcon />}
</button>
)}
</Collapsible.Trigger>
{/* ... */}
</Collapsible.Root>
);
};
Edit: 🤦🏻♂️ I was wrong, this doesn't work, because a function can't be passed from an RSC to a client component, it's not serializable, only components can be passed as props. |
No immediate plans, there are no equivalent workarounds at the moment and as of now asChild/Slot work great |
Dear Team, As we continue to develop and maintain our applications, it's important to adhere to modern best practices. Therefore, I would like to highlight that it is not advisable to use Legacy React APIs in our future projects. These APIs are deprecated and may be removed in future versions of React, which could lead to potential issues and increased maintenance effort. By using the latest React APIs, we can ensure our codebase is more robust, maintainable, and aligned with the latest standards. This approach will also help us leverage new features and improvements, contributing to better performance and developer experience. Let's prioritize updating any existing code that relies on Legacy APIs and focus on utilizing the current React API for all new development. |
You both mentioned legacy APIs and how they are deprecated. But legacy isn't equal to deprecated. Some things in software are considered legacy forever and that's totally fine. Do you have any source that says there are plans to deprecate cloneElement? React docs lists legacy APIs and deprecated ones: https://react.dev/reference/react/legacy, cloneElement is not deprecated at the moment. |
@robinmind786 we're not talking about |
@vladmoroz Could this pattern work as a replacement for It also has the benefit that |
@amannn do you have a minimal reproduction of your issue? To my knowledge Slot and asChild worked fine with server components (Slot isn't a client component even), so I'd be interested to look into it. |
Just had a minute to set up a reproduction. What I noticed is that only Here's the reproduction: StackBlitz |
Also when the child suspends due to usage of @vladmoroz Can we reopen this issue? |
@amannn thanks for the repro, I think opening a separate issue about async components would make sense |
@vladmoroz Got it, here you go: #3165 |
Question
We use Radix Primitives as the base for our components and
asChild
as a great benefit. Also, I imagineSlot
usescloneElement
as the main implementation.But, with
cloneElement
being considered a deprecated feature inside React, I wonder what plans are for supporting the same API with Radix Primitives.Moving to context or using render props?
I did not post this into StackOverflow because it's an important discussion for the community.
Thank you!
Reference for cloneElement alternatives: https://react.dev/reference/react/cloneElement#passing-data-through-context.
The text was updated successfully, but these errors were encountered: