Skip to content

Commit

Permalink
Fix bug with checkbox list causing infinite re-renders when panel tog…
Browse files Browse the repository at this point in the history
…gled
  • Loading branch information
codytodonnell committed Aug 29, 2024
1 parent 193d94a commit 5f8fd33
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
5 changes: 3 additions & 2 deletions strudel-taskflows/src/components/CheckboxList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export const CheckboxList: React.FC<CheckboxListProps> = ({
};

useEffect(() => {
console.log(checkValues)
if (onChange) onChange(checkValues);
if (onChange && checkValues?.length !== values?.length) {
onChange(checkValues);
}
}, [checkValues]);

useEffect(() => {
Expand Down
13 changes: 0 additions & 13 deletions strudel-taskflows/src/components/FilterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,10 @@ function filterReducer(state: FilterState, action: FilterAction): FilterState {
} else if (filter.value) {
activeFilters.push(filter);
}
console.log(activeFilters);
return {
...state,
activeFilters
}
// return {
// ...state,
// activeFilters: { ...state.activeFilters, [action.payload.field]: action.payload.value }
// }
}
case 'SET_ACTIVE_FILTERS': {
return {
Expand Down Expand Up @@ -95,14 +90,6 @@ export const FilterContext: React.FC<FilterContextProps> = ({
if (onChange) onChange(state.activeFilters);
}, [JSON.stringify(state.activeFilters)]);

/**
* If activeFilters is changed from outside the context (e.g. filters are reset)
* then the new value should be dispatched.
*/
// useEffect(() => {
// dispatch({ type: 'SET_ACTIVE_FILTERS', payload: activeFilters });
// }, [activeFilters]);

return (
<FilterContextAPI.Provider value={value}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion strudel-taskflows/src/pages/explore-data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Grid, Paper, Stack } from '@mui/material';
import { Box, Paper, Stack } from '@mui/material';
import React, { useState } from 'react';
import { FilterContext } from '../../components/FilterContext';
import { PageHeader } from '../../components/PageHeader';
Expand Down

0 comments on commit 5f8fd33

Please sign in to comment.