-
Notifications
You must be signed in to change notification settings - Fork 54
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
Allow non-booleans in the condition
prop as a convenience
#55
Comments
In case you are already using Babel to compile your JSX to JavaScript, may I suggest looking into Babel's optional chaining plugin as an alternative to relaxing the prop types? This would let you write the following instead: <When condition={state.data?.myProfile != null}>
My profile loaded!
</When> |
Please. This would be awesome. |
@Undeadlol1 Alright! I concede this could be convenient :) I cannot work on this at the moment, but feel free to send a PR with some test cases and I'll merge it. |
Yes, I set !! almost in all conditionals. |
+1 -- Still actual |
The lib has been entirely rewritten in order to have the source code in TypeScript and leveraging the "tsdx" package for bundling, testing and linting. BREAKING CHANGE: As part of the rewrite, the global exports are gone. Please use CommonJS or ESM style imports as specified in the README. fixes #55 closes #57
This is fixed with #66 which switches the code from JavaScript using prop-types to TypeScript. Now this doesn't mean that you have to write TypeScript yourself, but PropTypes won't complain anymore about not providing a non boolean value. The new type of condition is: export type BooleanLike = boolean | string | number | null | undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ComponentWithConditionProps
extends PropsWithChildren<{
condition: (() => BooleanLike) | BooleanLike;
}> {} This means it can be |
The lib has been entirely rewritten in order to have the source code in TypeScript and leveraging the "tsdx" package for bundling, testing and linting. BREAKING CHANGE: As part of the rewrite, the global exports are gone. Please use CommonJS or ESM style imports as specified in the README. fixes #55 closes #57
I see a lot of these warnings:
Because I will have conditions that look like:
With
state.data.myProfile
being an object that might look like:Which means that I have to do this to silence warnings:
Or:
Both of these solutions seems solvable if
react-if
accepted non-boolean conditions.null
andundefined
or anything non-truthy would be evaluated to afalse
.The text was updated successfully, but these errors were encountered: