insomnia/app/ui/components/rendered-text.js

44 lines
760 B
JavaScript
Raw Normal View History

2017-08-22 22:30:57 +00:00
// @flow
import React from 'react';
class RenderedText extends React.PureComponent {
props: {
component: string,
children: string,
2017-08-22 23:54:31 +00:00
render: Function,
props?: Object
2017-08-22 22:30:57 +00:00
};
state: {
renderedText: string
};
constructor (props: any) {
super(props);
this.state = {
renderedText: ''
};
}
async _render () {
const {render, children} = this.props;
const renderedText = await render(children);
this.setState({renderedText});
}
componentDidMount () {
this._render();
}
componentDidUpdate () {
this._render();
}
render () {
2017-08-22 23:54:31 +00:00
const {component, props} = this.props;
return React.createElement(component, props || {}, this.state.renderedText);
2017-08-22 22:30:57 +00:00
}
}
export default RenderedText;