javascript - How to generate React view from JSON response -


starting out react.js, have endpoint api backend returns json response. how access json inside of react component , loop through creating copies of other elements:

example: ...

class books extends react.component {   constructor() {     super();     // have access json here api   }    render() {    const books = jsonresponse.map((val) => {     <img src={jsonresponse.imgsrc} />     ...     });    return(     {books}    );    } 

so var books should render based on results json response

major problem: how data inside of class component, , possibly best way render it.

thanks

probably easiest (not best) way fetch data in componentdidmount or componentwillmount component lifecycle method. can choose wide range of libraries able fetch data. jquery, fetch, axios mention some.

you can find many tutorials simple google search. e.g.: https://daveceddia.com/ajax-requests-in-react/


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -