2017-11-05 7 views
0

제목에 connect 기능이있는 redux 저장소에 연결된 내 구성 요소에 제목이 표시되어 특정 상황의 상태 변경에 대한 업데이트가 트리거되지 않는 경우도 있습니다.redux 상태 변경시 구성 요소가 업데이트되지 않음

수정되는 상태에서 가변 내가가 react- 변하는 볼 수 정상적으로 발생하는 감속기의 IsChecked의 falue을 변경하려고하고

state: { 
    billDetails: { 
    productType1: {...}, 
    productType2: {...},   
    productType3: {...}, 
    productType4: { 
     accountId1 : [ 
     {invoiceNo:1, isChecked: true}, 
     {invoiceNo:2, isChecked: false} 
     ], 
     accountId2: [...] 
    } 
    } 
} 

다음 구조를 갖는다 네이티브 디버거가 있지만 구성 요소 자체가 업데이트되지 않습니다. 여기

객체 있도록 성분 billDetail: result(state, 'billUsage.billDetail', {})

+0

redux가 작업을 수행하도록 redux 상태를 디버깅 했습니까? – bitstrider

답변

0

Object.assign 복사 속성 값을 사용 mapStateToProps 함수에 billdetails 개체에 연결되어

{ 
    const { accountId, invoiceNo, isChecked } = action.payload; 
    const billDetails = result(state.billDetail, `${action.payload.productType}.${accountId}`, []); 
    const billDetailsModified = billDetails.map((bill) => { 
    if (bill.invoiceNo === invoiceNo) { 
     bill.isChecked = isChecked; 
    } 
    return bill; 
    }); 
    const newState = Object.assign({}, state); 
    newState.billDetail[action.payload.productType][accountId] = billDetailsModified; 
    return newState; 
} 

특정 케이스 내 감속기 코드로 코드 참조가 복사되므로 state.billDetail 및 newState.billDetail은 동일한 객체를 참조합니다. 따라서 원래 상태를 변경하면 상태는 not updating이됩니다.