@maqibin/react-use-lottery

1.0.2 • Public • Published

react-use-lottery

react hooks for lottery.

Installation

npm install @maqi1520/react-use-lottery

Usage

import useLottery from @maqi1520/react-use-lottery
import React from "react";

faker.setLocale("zh_CN");

const awards = [
  {
    name: "一等奖",
    count: 10,
    img: "/fc01a7a528f9c531.png",
    time: 10,
  },
  {
    name: "二等奖",
    count: 30,
    img: "/78bfc03faf8b1e2d.png",
    time: 5,
  },
  {
    name: "三等奖",
    count: 50,
    img: "/934dbc9de37038f2.png",
    time: 5,
  },
];

export default function App() {
    const users=[{ id: 1, name: "username" },...]
  const { toggle, award, showUsers, result } = useLottery(users, awards, {
    三等奖: [701, 702],
  });
  // 一次抽几个
  const currentNumber = award.count / award.time;
  const currentWinners = result[award.name] || [];

  console.log(result);

  return (
    <div>
      <button onclick={toggle}>toggle</button>
    </div>
  );
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @maqibin/react-use-lottery

Homepage

.

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

506 kB

Total Files

36

Last publish

Collaborators

  • maqibin