JSFiddle - React, Tailwind, and code Playground

HTML

<link rel="stylesheet" href="http://ivaynberg.github.io/select2/select2-3.5.1/select2.css">
<script src="http://ivaynberg.github.io/select2/select2-3.5.1/select2.js"></script>
<input type="hidden" id="select2-input" style="width:300px" />

JavaScript

$(document).ready(function() {
		$("#select2-input").select2({
			tags: [''],
			tokenizer: function(input, selection, callback) {

				// no comma no need to tokenize
				if (input.indexOf(',') < 0 && input.indexOf(' ') < 0)
					return;

				var parts = input.split(/,| /);
				for (var i = 0; i < parts.length; i++) {
					var part = parts[i];
					part = part.trim();

					callback({id:part,text:part});
				}
			}
		});
	});