@aaronlcj/use-last-fm 中文文档教程

发布于 4年前 浏览 23 项目主页 更新于 3年前

use-last-fm

CI Status

通过 last.fm 流式传输您当前正在播放的歌曲作为 React 挂钩。 来自 Alistair Smith - aliii

Features

  • Tiny: use-last-fm weighs in at less than 700 bytes minified and gzipped.
  • Universal: we dist esm and cjs modules.
  • ????‍Developer friendly: Helpful development messages that are stripped away in production
  • ⌨️ Strongly typed: use-last-fm is written in TypeScript and encourages good practices this way

Installation

With NPM

npm i --save @aaronlcj/use-last-fm

Or, with yarn:

yarn add @aaronlcj/use-last-fm

Usage

import { useLastFM } from 'use-last-fm';

const CurrentlyPlaying = () => {
  const lastFM = useLastFM({method: {type: 'user', node: 'recentlyPlayed'}, param: 'aabbccsmith'}, '[add api token here]');

  if (lastFM.status !== 'playing') {
    return <p>Not listening to anything</p>;
  }

  return (
    <p>
      Listening to {lastFM.song.name} by {lastFM.song.artist}
    </p>
  );
};

一个完整的例子可以在examples 文件夹

use-last-fm

CI Status

Stream your currently playing song through last.fm as a React hook. Forked from Alistair Smith - aliii

Features

  • ???? Tiny: use-last-fm weighs in at less than 700 bytes minified and gzipped.
  • ???? Universal: we dist esm and cjs modules.
  • ????‍???? Developer friendly: Helpful development messages that are stripped away in production
  • ⌨️ Strongly typed: use-last-fm is written in TypeScript and encourages good practices this way

Installation

With NPM

npm i --save @aaronlcj/use-last-fm

Or, with yarn:

yarn add @aaronlcj/use-last-fm

Usage

import { useLastFM } from 'use-last-fm';

const CurrentlyPlaying = () => {
  const lastFM = useLastFM({method: {type: 'user', node: 'recentlyPlayed'}, param: 'aabbccsmith'}, '[add api token here]');

  if (lastFM.status !== 'playing') {
    return <p>Not listening to anything</p>;
  }

  return (
    <p>
      Listening to {lastFM.song.name} by {lastFM.song.artist}
    </p>
  );
};

A full example can be seen in the examples folder

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文