React fetch data in server before render

前端 未结 8 2024
自闭症患者
自闭症患者 2020-12-02 18:29

I\'m new to reactjs, I want to fetch data in server, so that it will send page with data to client.

It is OK when the function getDefaultProps return dummy data like

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 19:10

    As a supplement of the answer of Michael Parker, you can make getData accept a callback function to active the setState update the data:

    componentWillMount : function () {
        var data = this.getData(()=>this.setState({data : data}));
    },
    

提交回复
热议问题