@@ -22,24 +22,33 @@ export function Dashboard() {
2222 ) ;
2323 }
2424
25+ let isApiSubscribed = true ;
2526 useEffect ( ( ) => {
2627 Query . selectRows ( {
27- containerPath : containerPath ,
28- schemaName : 'study' ,
29- queryName : 'demographics' ,
30- columns : 'Id,birth,death,gender/meaning,species,colony,calculated_status,u24_status,Id/age/AgeFriendly,Id/ageClass/label' ,
31- success : function ( results ) {
28+ containerPath : containerPath ,
29+ schemaName : 'study' ,
30+ queryName : 'demographics' ,
31+ columns : 'Id,birth,death,gender/meaning,species,colony,calculated_status,u24_status,Id/age/AgeFriendly,Id/ageClass/label' ,
32+ success : function ( results ) {
33+ if ( isApiSubscribed ) {
3234 setLiving ( results . rows . filter ( row => row . calculated_status === 'Alive' || row . calculated_status === 'alive' ) ) ;
3335 setu24Assigned ( results . rows . filter ( row => row . u24_status === true ) ) ;
3436 setDemographics ( results . rows ) ;
35- } ,
36- failure : function ( response ) {
37+ }
38+ } ,
39+ failure : function ( response ) {
40+ if ( isApiSubscribed ) {
3741 alert ( 'There was an error loading data' ) ;
38- console . log ( response ) ;
39- } ,
40- scope : this
41- } ) ;
42- } , [ ] /* only run the effect on mount */ ) ;
42+ console . error ( response ) ;
43+ }
44+ } ,
45+ scope : this
46+ } ) ;
47+
48+ return function cleanup ( ) {
49+ isApiSubscribed = false
50+ }
51+ } , [ ] ) ;
4352
4453 if ( demographics === null ) {
4554 return (
0 commit comments