I'm working on a Reactjs + React-motion project, in a "modal window" (let's say) I'd like to mount or load a component dynamically, if that's possible ?
My solution so far: I couldn't find a way, so it seems that it's easier to have the component in place, and hide it, then toggle a class or style on state change, revealing the hidden component and only after the "modal window" transition finishes.
Sharing some code below where it's easier to understand what I'm trying to do. There's no event handlers and most code was removed, but the onRest
(the event callback when the animation finishes is exposed) and also the render fn.
class HomeBlock extends React.Component {
constructor (props) {
...
}
...
motionStyleFromTo () {
return {
...
};
}
onRest () {
// this is triggered when the Motion finishes the transition
}
render () {
return (
<Motion onRest={this.onRestCallback.bind(this)} style={this.motionStyleFromTo()}>
{style =>
<div className="content" style={{
width: `${style.width}px`,
height: `${style.height}px`,
top: `${style.top}px`,
left: `${style.left}px`
}}>
[LOAD COMPONENT HERE]
</div>
}
</Motion>
);
}
}
export default HomeBlock;