Fix to only apply setState() when react component is mounted.