All Projects → remaxjs → hooks

remaxjs / hooks

Licence: other
小程序 API 的 hooks 封装

Programming Languages

typescript
32286 projects

remax-hooks(开发中)

小程序 API 的 hooks 封装。

示例

不用 hooks

import * as React from 'react';
import { View, getLocation } from 'remax/alipay';

export default () => {
  const [location, setLocation] = React.useState(null);
  const [error, setError] = React.useState(null);

  React.useEffect(() => {
    (async () => {
      try {
        const res = await getLocation({ type: 1 });
        setLocation(res);
      } catch(e) {
        setError(e);
      }
    })();
  }, []);

  return (
    <View>{!error ? <Text>{res ? res.city : '定位中...'}</Text> : '获取地理信息失败'}</View>
  );
};

用 hooks

import * as React from 'react';
import { View } from 'remax/alipay';
import { useLocation } from 'remax-hooks/alipay';

export default () => {
  const [res, error] = useLocation({ type: 1 });

  return (
    <View>{!error ? <Text>{res ? res.city : '定位中...'}</Text> : '获取地理信息失败'}</View>
  );
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].