From 49e72c687025d847f5a983005e70855142853af9 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Mon, 15 Aug 2016 16:54:55 +0300 Subject: Add QR size param --- index.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index e18098f..ac2d47f 100644 --- a/index.js +++ b/index.js @@ -2,36 +2,41 @@ import React from 'react' import ReactDOM from 'react-dom' import QRious from 'qrious' +import './base.scss' + class Qrgen extends React.Component { constructor (props) { super(props) this.state = { - 'text': 'abcde' + text: 'Hello World!', + size: 100 } } - updateQr () { - const qr = new QRious({ - element: document.getElementById('qr'), - value: this.state.text + componentDidMount () { + this.qr = new QRious({ + element: this.refs.qr, + value: this.state.text, + size: this.state.size }) } componentDidUpdate (prevProps, prevState) { - if (this.state.text != prevState.text) { - this.updateQr() - } + this.qr.value = this.state.text + this.qr.size = this.state.size } render () { return

qrgen

- + { - this.setState({ text: e.target.value }) + this.setState(Object.assign({}, this.state, { text: e.target.value })) + }}> + { + this.setState(Object.assign({}, this.state, { size: e.target.value })) }}> -

{this.state.text}

} } -- cgit v1.3.1