FunctionComponent.Of extend func cache key with 'Props type name #242
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.
User code that invokes
FunctionComponent.Of
can also be in generic context which makes caching by source FileName+LineNumber unsuitable: one function gets cached and resolved at runtime for different runtime types which results in runtime exceptions.I propose to add
'Props
type name to the cache key to fix that.You still can write code were wrong function will be picked up at runtime for the same 'Props argument type (e.g. if different
render
func values are passed from the outside), but it's less likely to happen.Ultimate solution would be to expose the fact that function is prepared and cached to the users and let them to specify their own unique cache key - or piggyback on existing
displayName
, which is also not ideal.