跳到主要内容

useWebp

判断能否使用 WebP 格式

何时使用​

无法判断该 WebP 在当前版本内是否可用时

API​

const canIUseWebp = useWebp();

返回值说明​

返回值说明类型
canIUseWebp是否可用boolean

代码演示​

basic/useWebp/index
import React from 'react';
import { useWebp } from 'taro-hooks';

import DemoContent from '@src/components/DemoContent';
import { Cell, Switch } from '@taroify/core';

export default () => {
const canIUseWebP = useWebp();

return (
<DemoContent>
<Cell.Group clickable>
<Cell title="是否可用WebP">
<Switch disabled checked={canIUseWebP} />
</Cell>
</Cell.Group>
</DemoContent>
);
};

Hook 支持度​

微信小程序H5ReactNative
✔️✔️✔️