How do I pass JSON data from a Node.js res.render method to react.js on the client

855 views Asked by At

I'm using node.js to accept a request, grab data from dynamodb, format/merge it into an existing JSON template object and return it.

This worked great when using node as a webservice and just returning json, but i'm testing writing new client side code in react.js. I know I could do two roundtrips - first to load the page without the JSON, then AJAX in react.js to load the JSON, but I'd like to do it in one.

In node I'm filling "filledTemplate" and I'd like to return the JSON object filledTemplate (via the Jade template "forms") to be accessible on the client side. I can pass the object to jade, but I'm not sure the next step after that.

            lib.pact.mergeDataIntoTemplate(formTemplateJSON,backgroundDatasetJSON, function(err, filledTemplate){
                if(err) {
                    console.log(err);
                }
                else{
                    res.render('forms', { title: 'Filled Forms', data: filledTemplate });
                }
        });

Long story short, I'm not sure how to pass/access the object in react.js (or vanilla js for that matter) on the client side.

Any tips or pointers would be much appreciated.

(also, apparently there's no tag for react.js, and I can't add it... if someone else wants to)

0

There are 0 answers