Making REST calls from a react component

前端 未结 4 1834
醉酒成梦
醉酒成梦 2021-01-30 17:30

I am trying to make REST call from a react component and render the returned JSON data into the DOM

Here is my component

import React from \'react\';

ex         


        
4条回答
  •  没有蜡笔的小新
    2021-01-30 17:57

    You can try this for your render method:

    render() {
        var resultNodes = this.state.items.map(function(result, index) {
            return (
                
    result
    ); }.bind(this)); return (
    {resultNodes}
    ); }

    and don't forget to use .bind(this) for your fetch(...).then(), I don't think it could work without...

提交回复
热议问题