-
Notifications
You must be signed in to change notification settings - Fork 58
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
FED-1978 Null-safe props documentation #916
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
@@ -0,0 +1,411 @@ | |||
# Null safety and required props |
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.
GitHub's "rich diff" viewer apparently doesn't render alerts very well, so I'd recommend viewing this file directly: https://github.com/Workiva/over_react/blob/null-safety-docs/doc/null_safety_and_required_props.md
@@ -243,11 +243,17 @@ The use-case for composing multiple props mixins into a single component props c | |||
|
|||
#### UiProps as a Map | |||
|
|||
> [!WARNING] |
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.
GitHub's "rich diff" viewer apparently doesn't render alerts very well, so I'd recommend viewing this file directly: https://github.com/Workiva/over_react/blob/null-safety-docs/README.md#uiprops-as-a-map
__There have been a lot of fantastic [improvements in this library recently](https://pub.dev/packages/over_react#-changelog-tab-)__, all of which require some action on your part if you have existing components built prior to the `3.1.0` release of OverReact. __We've done everything we can to make the migrations as painless as possible__ - with the vast majority of changes being handled by some codemod scripts you can run in your libraries locally. As always, if you encounter issues while working through the migration, you can reach out to us in [our gitter chat](https://gitter.im/over_react/Lobby), or [open a new issue][new-issue]. | ||
|
||
__First, you should upgrade your components to `UiComponent2`__. Check out the [`UiComponent2` Migration Guide](doc/ui_component2_transition.md) to learn about the benefits of `UiComponent2`, the codemod script you can run, and other updates you may need to make manually. | ||
|
||
__Once you have migrated your components to `UiComponent2`__, you're ready to start using the "v3" component boilerplate - which is a _massive_ quality of life improvement for component authors! Check out the [Component Boilerplate Migration Guide](doc/new_boilerplate_migration.md) to learn about the benefits of the new boilerplate, the codemod script you can run, and other updates you may need to make manually. |
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.
All this info (that's still relevant) is captured in the other migration guides
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.
This is great! Just found a couple of things...
bool? isDisabled; | ||
Iterable<String>? items; |
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.
Is there a reason these are nullable here, but not on line 817-818?
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.
In those lines, they're props that are defaulted in a class component's defaultProps
, whereas here, they're defaulted in a function component
/// UiFactory<FancyInputProps> FancyInput = uiForwardRef( | ||
/// (props, ref) { |
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.
Since we're using a ref declared in props instead of the forwarded ref, we probably should just make this uiFunction
/// UiFactory<FancyInputProps> FancyInput = uiForwardRef( | |
/// (props, ref) { | |
/// UiFactory<FancyInputProps> FancyInput = uiFunction( | |
/// (props) { |
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.
Actually, the ref passed to a component isn't available in props.ref
and so I believe you need to use forwardRef to use useImperativeHandle
(see React docs here)
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.
These docs are great!! Really clear and helpful! I just had some minor comments
OverReact supports providing defaults for optional props in the following cases: | ||
|
||
| Nullability | Class Component | Function component | | ||
|--------------|-----------------|--------------------| | ||
| Non-nullable | Yes<sup>1</sup> | No | | ||
| Nullable | Yes | Yes<sup>2</sup> | | ||
|
||
1. _Props are declared the same way required props are_ | ||
2. _Easiest when `null` is treated the same as the default_ |
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.
This is a great explanation! I was expecting the following subsections to map to the three Yes
boxes, but it seemed kind of unclear - could there be an example here (like maybe the last example - line 343) or links to the different sections or maybe rename the sections so it's really easy to find an example of each of these situations in the table?
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 took a stab and making this clearer, and also added a bit more content: d14ca46
|
||
### Defaulting nullable props using `??` | ||
|
||
In over_react function components, prop defaulting for nullable props is typically implemented using null-aware `??` operators. As a result, unspecified props and explicit `null` values are treated the same. |
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.
Is this also how you default nullable props in class components or is it only a function component thing? maybe the section headers could be updated depending on which is the case
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.
It's a function component thing, but you can also do this in class components. I think I had originally written the header in a way to not exclude class components; I'll try updating this to be clearer
Okay @aaronlademann-wf and @sydneyjodon-wk, I think I've addressed all your feedback! |
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.
+10 Looks great to me!!
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.
@Workiva/release-management-pp
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.
+1 from RM
Motivation
We needed some documentation on required props and how they relate to null safety.
We also need to update code blocks in documentation to use null safety.
Changes
Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: