How to fetch data when a React component prop changes?

前端 未结 4 1189
孤街浪徒
孤街浪徒 2020-12-04 16:30

My TranslationDetail component is passed an id upon opening, and based on this an external api call is triggered in the class constructor, receiving data to the state, and t

4条回答
  •  难免孤独
    2020-12-04 17:10

    I would use the render method. If the data is not loaded I would render a loader spinner and throw the action that fetch de data. For that i usually use the stores. Once the store has de data from the api, mark the data as loaded, throw an event and let the component get the data from the store, replacing the loader spinner with your data representation.

提交回复
热议问题