-
Notifications
You must be signed in to change notification settings - Fork 53
feat(factories): use children
in shorthands as render props
#1951
Conversation
this looks awesome! Migration would be a bit tricky for the consumers though, let'see how we can handle that. |
passing the render down the tree, even though strange, was used for a reason - if the shorthand props are resolved asynchronously. Do you see a good solution in this case, or should the recommendation only be to move the state up and resolve everything before rendering? |
Lift up state, with hooks it will be easier. It also will solve issues like re-positioning requirement. |
children
in shorthands as render props
Codecov Report
@@ Coverage Diff @@
## master #1951 +/- ##
==========================================
+ Coverage 75.83% 75.85% +0.02%
==========================================
Files 160 160
Lines 5569 5571 +2
Branches 1611 1630 +19
==========================================
+ Hits 4223 4226 +3
+ Misses 1332 1331 -1
Partials 14 14
Continue to review full report at Codecov.
|
|
||
export type ShorthandValue<P extends Props> = | ||
| ReactNode | ||
| Props<P> & { children?: P['children'] | ShorthandRenderProp<P> } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miroslavstastny I am not sure about this typing, any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 😃
…stardust-ui/react into rfc/render-props # Conflicts: # CHANGELOG.md
⏩ Migration
We decided to go with soft migration, existing API with render callback will be deprecated and will create warnings.
Case 0: slot replacement
Used when you need to replace a component in a slot, for example replace
Button
withSplitButton
inDialog
.Before
After
Case 1: wrapping slot
Used when you need to wrap component slot with
Popup
orTooltip
, for example.Before
After
Case 2: wrapping item
Used when you need to wrap the whole item with
Popup
orTooltip
, for example.Before
After
Case 3: delayed execution
Is used in async scenarios. We deprecated this use case, see Motivation part. There is only one way to migrate is to lift up state, it works even now.
CodeSandbox with Before & After: https://codesandbox.io/s/stardust-ui-example-23icy
Before
After
⌚️ Motivation
Existing API with
render
callback is very powerful and in the same time is over-complicated: it's hard to explain to people how it works and it's hard to use for frequent use cases.Other cons
render
down into React tree:kind
prop is broken:⭐️ Solution
React has well known
render props
pattern and I suggest to use instead as more friendly option.I propose to have only one type of usage, via
children
prop:It still allows to pass shorthand props.