Refactor inline spaghetti jQuery code to ReactJS