How to fetch data when a React component prop changes?

前端 未结 4 1188
孤街浪徒
孤街浪徒 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 16:52

    Use componentWillMount to get the data and set the state. Then use componentWillReceiveProps for capturing update on the props.

    You can check the Component Specs and Lifecycle.

提交回复
热议问题