componentDidUpdate(prevProps) { if (prevProps.rootdir !== this.state.cwd && prevProps.rootdir !== this.props.rootdir) { //Perform some operation this.setState({ cwd: prevProps.rootdir, rootDir: prevProps.rootdir }, () => { term.clear(); term.write(this.state.cwd + '\r\n' + '$'); shell.cd(this.state.cwd); }); } }