taro-hooks
Version:
为 Taro 而设计的 Hooks Library
24 lines • 956 B
JavaScript
var _excluded = ["textStyle"];
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import { setBackgroundColor, setBackgroundTextStyle } from '@tarojs/taro';
import { useEffect } from '@taro-hooks/core';
import usePromise from '../usePromise';
function useBackground(option) {
var setColor = usePromise(setBackgroundColor);
var setStyleAsync = usePromise(setBackgroundTextStyle);
var setStyle = function setStyle(textStyle) {
return setStyleAsync({
textStyle: textStyle
});
};
useEffect(function () {
if (option) {
var textStyle = option.textStyle,
colorOption = _objectWithoutPropertiesLoose(option, _excluded);
setColor(colorOption);
textStyle && setStyle(textStyle);
}
}, [option]);
return [setColor, setStyle];
}
export default useBackground;