@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
41 lines • 1.64 kB
JavaScript
;
/** HOC to cache a props value and pass a transformed value to the child.
* When the input value changes, transform it and pass it along. If no
* transform is specified, then pass it through directly. All other props
* are passed through. Transforms are asynchronous. Essentially, this allows
* you to cache some data as state passed through props but is expensive to obtain.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = require("react");
class FetchDataComponent extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
value: this.props.initialValue,
loading: false
};
}
shouldComponentUpdate(nextProps, nextState) {
const s = nextProps.value !== this.state.value;
console.log("shouldupdate", nextProps, nextState, s);
return s;
}
componentWillReceiveProps(nextProps) {
console.log("receive new props", nextProps);
}
//static propTypes = {
// children: React.PropTypes.func.isRequired,
//}
render() {
const _a = this.props, { initialValue } = _a, passThrough = tslib_1.__rest(_a, ["initialValue"]);
if (this.props.children && React.Children.count(this.props.children) === 1) {
const child = React.Children.only(this.props.children);
return React.cloneElement(child, Object.assign({}, passThrough));
}
else
return null;
}
}
exports.FetchDataComponent = FetchDataComponent;
//# sourceMappingURL=FetchDataComponent.js.map