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' ;
210import AnnotationOperation from '@labelbee/lb-components' ;
311import '@labelbee/lb-components/dist/index.css' ;
412import { 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