Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for React #6

Closed
kozakdenys opened this issue Aug 26, 2019 · 1 comment
Closed

Add support for React #6

kozakdenys opened this issue Aug 26, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@kozakdenys
Copy link
Owner

No description provided.

@kozakdenys kozakdenys added enhancement New feature or request and removed improvement labels Sep 9, 2019
@kozakdenys
Copy link
Owner Author

It works well with React.
An example of React app:

import QrCodeStyling from 'qr-code-styling';
import React from 'react';

class App extends React.Component {
    constructor(props) {
        super(props);
        this.handleDataChange = this.handleDataChange.bind(this);
        this.updateQr = this.updateQr.bind(this);
        this.qrRef = React.createRef();
        this.state = {
            data: "init"
        };
        this.qrCode = new QrCodeStyling({
            width: 300,
            height: 300,
            data: this.state.data,
            image: "https://facebookbrand.com/wp-content/themes/fb-branding/assets/images/fb-logo.png?v2",
            dotsOptions: {
                color: "#4267b2",
                type: "rounded"
            },
            backgroundOptions: {
                color: "#e9ebee",
            }
        });
    }

    handleDataChange(event) {
        const target = event.target;

        this.updateQr(target.value);
        this.setState({
            data: target.value
        });
    }

    updateQr(data) {
        this.qrCode.update({
            data
        });
    }

    componentDidMount() {
        this.qrCode.append(this.qrRef.current);
    }

    render(){
        return (
            <div>
                <input
                    name="data"
                    type="text"
                    value={this.state.data}
                    onChange={this.handleDataChange} />
                <div ref={this.qrRef} />
            </div>
        )
    }
}

export default App

standardspace pushed a commit to standardspace/qr-code-styling that referenced this issue Nov 29, 2023
…rn/http-proxy-1.18.1

Bump http-proxy from 1.18.0 to 1.18.1
ChielTimmermans referenced this issue in sallandpioneers/qr-code-styling Jul 11, 2024
Allow multiple QR codes with different data to render simultaneously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant