This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 259
Output javascript objects? #41
Comments
I got a solution,do I miss the better way? <script data-data={JSON.stringify(this.props.users)} dangerouslySetInnerHTML={{__html:`
var data = JSON.parse(document.currentScript.dataset['data']);
console.log(data);
`}}/> |
Something like this should work: <script dangerouslySetInnerHTML={{__html: `
var json = ${JSON.stringify(this.props.users)};
var data = JSON.parse(json);
console.log(data);
`}}/> |
@spicyj Works like a charm!Where can I find the docs for this |
It's a feature of ES6 (backtick) template literals, which you're using. |
@spicyj That's right!How come I don't think in that way,thanks man! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How to output javascript objects so we could use it for front-end pages?
maybe like this:
The text was updated successfully, but these errors were encountered: