Skip to content

get base64 string #41

@mdodge-ecgrow

Description

@mdodge-ecgrow

I'm trying to figure out how to just get the base64 string from my Barcode component. I can create the barcode on the page and if I copy the image location, I can see the actual base64 string that I want. https://codesandbox.io/s/determined-hawking-ow9mk
<Barcode value={'72527273070'} renderer={'img'} />
But how do I get that string in code? This is what I've tried:

const encodeSvg = reactElement => {
	return (
		'data:image/png;base64,' +
		escape(ReactDOMServer.renderToStaticMarkup(reactElement))
	);
};

const barcode = encodeSvg(
	<Barcode value={'72527273070'} renderer={'img'} />
);

console.log(barcode);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions