UNPKG

taro-hooks

Version:
24 lines 956 B
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;