Convert XYFrame from class to function component #606
Merged
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.
Alright, this one might seem messy, gonna try to describe all the details I've encountered.
The main reason to do this right now was the idea to make top level frames responsive by default (see #601). It would be a neat trick if it was possible by just changing the behavior inside
<Frame />
, but what makes it not that easy is that<XYFrame />
and others also needsize
as a part of their rendering phase. Thus, the proper place to modify to responsive-by-default behavior are those actual frames. Recently introduced hook for element size is great, but can't be used by class components. I have zero motivation to implement something new for class components, so the only way to go is to convert the rest of classes to functions.There are a bunch of aspects I noticed that are similar to all top level frames that are currently implemented as classes:
getDerivedStateFromProps
to change the state based on changed props and none of them actually have state (that is controlled bysetState
)constructor
and additional mechanic is implemented ingetDerivedStateFromProps
to avoid any possibility to rewrite existing state if underlying data from props haven't changed.onUnmount
prop. I'm seeing that some frames have this prop and I'm not sure about how it is supposed to be used (or should it be used by the users at all). in any case, I'd consider getting rid of it as it's domain itself is defined based on the notion and assumptions of class components. Basically, it feels like a code smell. cc @emeeksTechnically it wasn't hard to convert
<XYFrame />
to function component. But there are still plenty of things to change inside this new component to make it benefiting more from being a function. These can be addressed in the following PRs:props
andstate
onUnmount
prop