12345678910111213141516171819202122232425262728 |
- import React from 'react';
-
- export default (props) => {
- const { text, width = 200, height = 200 } = props;
-
- const ref = React.useRef();
- const qrRef = React.useRef();
-
- React.useEffect(() => {
- if (text) {
- if (qrRef.current) {
- qrRef.current.clear();
- qrRef.current.makeCode(text);
- } else {
- qrRef.current = new QRCode(ref.current, {
- text,
- width,
- height,
- correctLevel: QRCode.CorrectLevel.Q
- });
- }
- }
- }, [text, width, height]);
-
- return (
- <div ref={ref}></div>
- )
- }
|