文档

qrcodejs

示例

  1. import React, { useState, useEffect, useRef } from 'react';
  2. import QRCode from 'qrcode';
  3. function GenerateQrCode() {
  4. const [codeInts] = useState(useRef(null));
  5. useEffect(() => {
  6. if (codeInts.current) {
  7. new QRCode(codeInts.current, {
  8. text: "xxx.com",
  9. width: 128,
  10. height: 128,
  11. colorDark : "#000000",
  12. colorLight : "#ffffff",
  13. correctLevel : QRCode.CorrectLevel.H
  14. });
  15. }
  16. }, [codeInts]);
  17. return (
  18. <div ref={codeInts} />
  19. );
  20. }
  21. export default GenerateQrCode;