Geddit-Inc / Beta-version

Community evaluation for online coding classes
0 stars 4 forks source link

reference backend json in reactjs #7

Open cookies4u opened 7 years ago

cookies4u commented 7 years ago
var data = { a: 1, b: 2 };

var Hello = React.createClass({
    render: function() {
        return <div><pre>{JSON.stringify(data, null, 2) }</pre></div>;
    }
});

React.render(<Hello />, document.getElementById('container'));

http://stackoverflow.com/questions/30765163/pretty-printing-json-with-react

cookies4u commented 7 years ago

backtofront

chocopuff2020 commented 7 years ago

@cookies4u ohhhhh wow . Thank you!! This is so nice!!! Could you explain the steps for us? I can't read what's in the box :P ...

cookies4u commented 7 years ago

so passing a json array of objects to react is not as simple as handlebars. We have 3 options. The hardest option is using something like redux The simpler option due to our time constraint is like the diagram in the image above. We can use a fetch or $.ajax call within the onClick event The code on the bottom right is how it may potentially look (will have to tweak). Mike said you guys may be familiar with setState. Note: list is just the api route. In our case it would be api/courses

cookies4u commented 7 years ago

The fetch command basically refresh the react module