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

[Advanced React] Components as props - Add flexibility #74

Open
reboottime opened this issue Apr 27, 2024 · 2 comments
Open

[Advanced React] Components as props - Add flexibility #74

reboottime opened this issue Apr 27, 2024 · 2 comments

Comments

@reboottime
Copy link
Owner

reboottime commented Apr 27, 2024

Component as Props

This article is part of an advanced React series tutorials.

Trade off: Having flexibility but too flexible

Major Content

  • React.cloneElement and its alternatives
  • Element as props
@reboottime
Copy link
Owner Author

reboottime commented Apr 27, 2024

The Problem And Solution

  • Button example: In an ship fast env with frequent change requirements, a button component may look like this
image image image
  • Modal example
image

@reboottime
Copy link
Owner Author

reboottime commented Apr 28, 2024

View From Performance Perspective

  • The footer is not a performance matter as it just sits in memory
image
  • React.cloneElement is a performance matter, way too fragile and magical on one or two params
image

Solution: https://react.dev/reference/react/cloneElement#alternatives

<List
 items={products}
 renderItem={(product, isHighlighted) =>
   <Row
     key={product.id}
     title={product.title}
     isHighlighted={isHighlighted}
   />
 }
/>

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

No branches or pull requests

1 participant