-
Notifications
You must be signed in to change notification settings - Fork 87
feat: Print function children #607
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
Open
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Pass prop name as second argument in `functionValue` option - Accept filter function in `showFunctions`
@gabiseabra
gabiseabra
changed the title
(削除) feature(formatting) print function children (削除ここまで)
(追記) feat: Print function children (追記ここまで)
Apr 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was another attempt to fix this (#338) which I suppose wasn't merged because the author didn't address an issue raised about calling function children in order to print them.
This is fine for pure functions that return react elements, but you can't guarantee that function children always behave like this, so this could cause problems for users who have unconventional function children.
Another approach could be printing the function's source, but since sources are subject to transpilation by babel before runtime, just printing the function's body wouldn't yield JSX.
Or you could use source maps to print the original code instead, but printing JSX code as string has its own limitations as the output isn't parsed and formatted by this library.
As each of these methods have their own trade-offs, I've decided to go for a less opinionated solution and leave this decision up to the library user. Functions as children will work the same as if they were any other prop, users can choose how to format them using
functionValue
andshowFunctions
options.Additionally, I've altered both these options to provide more granularity on if and how each function prints since users may want to handle render props differently than other function props.
What I did:
prop
param tofunctionValue
optionshowFunctions
function option to filter prop by prop