Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 4x 12x 12x 12x 12x 12x 12x | /*
* @Describe: 设置组件预定义props的方法
* @Author: kexu9
* @Date: 2021-04-27 10:08:49
* @Last Modified by: kexu9
* @Last Modified time: 2021-05-18 22:02:07
*/
import React from 'react';
function withProps<CP>(
Component: React.FC<CP>,
predefineProps: CP,
options?: {
mergeFunction?: (predefineProps: CP, props: CP) => CP;
debug?: boolean;
}
) {
return function component(props: CP): JSX.Element {
const {mergeFunction, debug} = options || {};
let finallyProps = props;
Eif (mergeFunction) {
finallyProps = mergeFunction(predefineProps, props);
} else {
finallyProps = {...predefineProps, ...props};
}
Iif (debug) {
// eslint-disable-next-line no-console
console.debug(finallyProps, 'withProps_finallyProps');
}
return <Component {...finallyProps} />;
};
}
export default withProps;
|