AJAX request should be done at the componentDidMount hook when you need to load data inmediatelly after the component is first rendered. When you wish to refresh the data after some props changed, you must use the componentDidUpdate hook.
But you'll have to take hand of another three lifecycle hooks to avoid starting an infinite loop of requests/updates. Assuming you wish to update a posts list based on props.category changes:
stateshould have two properties,categoryandcurrentCategory, set to null on the component's constructor;getDerivedStateFromPropsis needed to updatestate.categoryfrom the newprops.category;shouldComponentUpdateis needed to compare bothstate.categoryandstate.currentCategoryto determine if the component should be updated;getSnapshotBeforeUpdateis needed to determine ifcomponentDidUpdateshould make an AJAX request or to change thestate.currentCategoryvalue and finish the updating cycle.
getDerivedStateFromProps and getSnapshotBeforeUpdate were introduced in React v16.3.0.