Let's say I've got a Tooltip component that shows & hides depending on whether there is text data for it or not:
{this.state.tooltipText && (
<Tooltip
text={this.state.tooltipText} />
)}
If I wanted to transition this component in and out, I might instead include a boolean on
prop and let the component manage transitioning out itself.
<Tooltip
on={this.state.tooltipText !== null}
text={this.state.tooltipText} />
With this setup, though, I lose the text
prop right when the transition out should begin. There is very clearly never a state where on
is false
and I still have access to the text
prop.
Is there a good way to handle this scenario?
- Should the component keep an internal record of the previous state of
tooltipText
? - Or is it best to use two properties to track the state of the tooltip (
tooltipOn
andtooltipText
) and never erasethis.state.tooltipText
?