Skip to content

Commit 63de7d1

Browse files
committed
fix: The params named projectList is getted error.
It causes that user enter project on the error page
1 parent 369ffc7 commit 63de7d1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Annotation/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import React, { useContext } from 'react';
1+
/*
2+
* Annotation Component
3+
* @Author: Laoluo [email protected]
4+
* @Date: 2022-05-23 19:15:58
5+
* @LastEditors: Laoluo [email protected]
6+
* @LastEditTime: 2022-05-24 10:43:53
7+
*/
8+
9+
import React, { useContext, useRef } from 'react';
210
import AnnotationOperation from '@labelbee/lb-components';
311
import '@labelbee/lb-components/dist/index.css';
412
import { EIpcEvent } from '../constant/event';
@@ -12,6 +20,7 @@ const Annotation = (props: any) => {
1220
dispatch,
1321
state: { currentProjectInfo, projectList, fileList },
1422
} = useContext(AnnotationContext);
23+
const cacheProjectList = useRef(projectList); // TODO: I will rewrite by custom hook later
1524

1625
const onSubmit = (data: any[], submitType: any, i: number) => {
1726
// 翻页时触发当前页面数据的输出
@@ -44,9 +53,11 @@ const Annotation = (props: any) => {
4453
};
4554

4655
const updateProjectInfo = (info: { imgIndex?: number; step?: number }) => {
47-
const newProjectList = projectList.map((item) => {
56+
// Notice: The value of context(e.g. projectList) is not updated
57+
const newProjectList = cacheProjectList.current.map((item) => {
4858
return item.id === currentProjectInfo?.id ? { ...item, ...info } : item;
4959
});
60+
cacheProjectList.current = newProjectList; // need to update
5061
dispatch({
5162
type: 'UPDATE_PROJECT_LIST',
5263
payload: { projectList: newProjectList },

0 commit comments

Comments
 (0)