1.0.1 • Published 10 months ago

@jswork/react-qrcode v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

react-qrcode

Qr code for react.

version license size download

installation

npm install -S @jswork/react-qrcode

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
valuestringfalse-The qr value.
optionsobjectfalse-The qrcodejs options.

usage

  1. import css

    @import "~@jswork/react-qrcode/dist/style.css";
    
    // or use sass
    @import "~@jswork/react-qrcode/dist/style.scss";
    
    // customize your styles:
    $react-qrcode-options: ()
  2. import js

    import ReactDemokit from '@jswork/react-demokit';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactQrcode from '@jswork/react-qrcode';
    import './assets/style.scss';
    
    class App extends React.Component {
      state = {
        value: 'https://www.baidu.com'
      };
    
      changeValue = () => {
        console.log('set new value!');
        // [195, 217]
        //(BUG:) https://github.com/davidshimjs/qrcodejs
        var url = 'https://www.baidu.com&redirect=https%3A%2F%2Fwww.baidu.com%2Findex.html%3Fsdflsjfdjslsdlfjlsdjflksjdfkljsdklfjskldjfklsdjfkljsdklfjskldjfklsdjflssldjflsdjflksjdfljsdlfjsdjf%2Blksdjflksdjfklsjdfkljsdlfjlfjslkdfsdlfjsdlfjsdlfjlsdfjsldfjkljldsfj'.slice(
          0,
          197
        );
    
        // console.log(url.length);
        this.setState({ value: url });
      };
    
      render() {
        const { value } = this.state;
        return (
          <ReactDemokit
            className="p-3 app-container"
            url="https://github.com/afeiship/react-qrcode">
            <ReactQrcode value={value} />
            <button className="button is-primary my-2" onClick={this.changeValue}>
              Regenerate
            </button>
          </ReactDemokit>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

documentation

resources

license

Code released under the MIT license.