var React = require('react'),
    ioBarcode = require("io-barcode");

module.exports = React.createClass({
  propTypes: {
    code: React.PropTypes.string.isRequired
  },
  componentDidMount() {
    var placeholder = React.findDOMNode(this.refs.placeholder);
    try {
      var canvas = ioBarcode.CODE128B(
        this.props.code,
        {
          displayValue: true,
          height: 50,
          fontSize: 18
        }
      );
      placeholder.appendChild(canvas);
    } catch (e) {
      console.error(e);
      placeholder.innerText = "您輸入的字無法編成條碼";
    }

  },
  render() {
    return (
      <div ref="placeholder" />
    )
  }
});
var React = require('react'),
    ioBarcode = require("io-barcode");

module.exports = React.createClass({
  propTypes: {
    code: React.PropTypes.string.isRequired
  },
  componentDidMount() {
    var img = React.findDOMNode(this.refs.img);
    try {
      var canvas = ioBarcode.CODE128B(
        this.props.code,
        {
          displayValue: true,
          height: 50,
          fontSize: 18
        }
      );
      img.src = canvas.toDataURL();
    } catch (e) {
      console.error(e);
      img.alt = "您輸入的字無法編成條碼";
    }

  },
  render() {
    // Canvases are not printable, but images are.
    //
    return (
      <img ref="img" />
    )
  }
});
Use img instead of canvas to make barcodes printable
Use img instead of canvas to make barcodes printable