Suscribe in life cicle method

The source code hase marks, the question in mark 2:

  1. Subscription to orders
  2. When downloading a page, the subscription to the tasks of the first order, not working why? (I tried doing this in componentDidUpdate and in getDerivedStateFromProps
    why does not it happen)
  3. Unsubscription from the tasks of the previous order, subscription to the tasks of the current order. Working.

class App extends Component {

constructor(props) {
super(props);
this.state = {selectedOrder: null, taskSuscriber:null};
console.log(“constructor”);
}

componentDidUpdate(prevProps, prevState, snapshot)//static getDerivedStateFromProps(nextProps, prevState)
{
if(this.state.taskSuscriber==null && this.props.orders.length > 0){
let handler = Meteor.subscribe(‘tasks’, this.props.orders[0]._id, {// ------------- 2. Not working
onReady: () => { this.log(); },
onError: () => { console.log(“onError”, arguments); }
});
this.setState({selectedOrder: this.props.orders[0], taskSuscriber: handler,});
}
}

setSelected(order) ------------- 3. Working
{
if(this.state.taskSuscriber!=null)
this.state.taskSuscriber.stop(); // need remember about ready()
let _taskSuscriber = Meteor.subscribe(‘tasks’, order._id, {
onReady: () => { this.setState( {selectedOrder: order, taskSuscriber: _taskSuscriber}); },
onError: () => { console.log(“onError”, arguments); }
});
}

render() {
console.log(“App render()”);
if(!this.props.orders || this.props.orders.length <= 0 || this.state.selectedOrder == null) return null;

var res = (
	      <div> 
			   <OrdersContainer orders={this.props.orders} setSelected={this.setSelected.bind(this)} > </OrdersContainer>
			   <TaskContainer tasks={this.props.tasks} selectedOrder = {this.state.selectedOrder}/>
          </div>
   ); 
return  res;  

}
}

export default withTracker(() => {
const handle = Meteor.subscribe(‘orders’); ------------- 1.
let orders = Orders.find({}, { sort: { createdAt: -1 }}).fetch();
let tasks = Tasks.find().fetch();
return { orders: orders, tasks: tasks,};
}
)(App);

How can I remove this topic?

You can’t, but if you have solved it, you can edit the title to add [SOLVED]. If you update the thread with what you did it may help others.