Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: rewrite some effect-state updates as functional updates #426

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/SiteHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const SiteHeader = () => {
const [modalVisible, setModalVisible] = useState(false);

const toggleModalVisibility = useCallback(() => {
setModalVisible(!modalVisible);
}, [modalVisible]);
setModalVisible((v) => !v);
}, []);

const performSignOut = usePerformSignOut();

Expand Down
4 changes: 2 additions & 2 deletions src/components/discovery/DiscoveryQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ const DiscoveryQueryBuilder = ({ activeDataset, dataTypeForms, requiredDataTypes
);

const handleHelpAndSchemasToggle = useCallback(() => {
setSchemasModalShown(!schemasModalShown);
}, [schemasModalShown]);
setSchemasModalShown((s) => !s);
}, []);

const handleSetFormRef = useCallback(
(dataType, form) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/explorer/IndividualTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ const IndividualTracks = ({ individual }) => {
if (!igvBrowserRef.current) return;

const wasViewing = track.viewInIgv;
setAllTracks(allTracks.map((t) => (t.filename === track.filename ? { ...track, viewInIgv: !wasViewing } : t)));
setAllTracks((at) => at.map((t) => (t.filename === track.filename ? { ...track, viewInIgv: !wasViewing } : t)));

if (wasViewing) {
igvBrowserRef.current.removeTrackByName(track.filename);
} else {
igvBrowserRef.current.loadTrack(buildIgvTrack(igvUrls, track)).catch(console.error);
}
},
[allTracks, igvUrls],
[igvUrls],
);

const storeIgvPosition = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/components/manager/drs/ManagerDRSContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ const ManagerDRSContent = () => {
}, [performSearch, searchValue]);

useEffect(() => {
setSelectedRowKeys(selectedRowKeys.filter((k) => k in objectsByID));
}, [selectedRowKeys, objectsByID]);
setSelectedRowKeys((s) => s.filter((k) => k in objectsByID));
}, [objectsByID]);

const onDeleteSelected = useCallback(() => {
Modal.confirm({
Expand Down
8 changes: 4 additions & 4 deletions src/components/manager/projects/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ const Project = ({

useEffect(() => {
if (value) {
setProjectState({
...projectState,
setProjectState((ps) => ({
...ps,
...value,
data_use: simpleDeepCopy(value.data_use || INITIAL_DATA_USE_VALUE),
});
}));
}
}, [value, projectState]);
}, [value]);

const handleSave = useCallback(() => {
const form = editingForm.current;
Expand Down