Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    1 Case khó hiểu trong redux, mong được ace giúp đỡ.

    ReactJS
    0
    5
    510
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Hai Dang Vu last edited by

      Sau bao lâu làm việc với React-native thì quay về React web.và gặp 1 case này.không biết có ace nào gặp chưa là:
      "Reducer có update nhưng component ko rerender lúc update mà chỉ rerender khi reducer được restore lại với initialState"
      Redux-logger có log ra nhưng prev state lại ko khác gì next state khi update reducer, nhưng lại khác khi reducer được restore lại với initialState.
      1 số hình ảnh ạ:
      alt text
      alt text
      alt text
      Mong ace giải đáp.mình xin cảm ơn.

      1 Reply Last reply Reply Quote 0
      • Kha Pham
        Kha Pham last edited by

        Mình thì không giỏi lắm. nhưng bạn cứ thêm return vào trước newState xem thế nào

        Đam mê công nghệ
        Không biết nhiều nhưng cũng muốn đóng góp

        1 Reply Last reply Reply Quote 0
        • H
          Hai Dang Vu last edited by

          thanks bạn cơ mà nó cũng nằm trong những hạ sách mình thử rồi :v

          Kha Pham 1 Reply Last reply Reply Quote 0
          • Kha Pham
            Kha Pham @Hai Dang Vu last edited by

            @Hai-Dang-Vu đầy là reducer của mình hơi cùi nhưng mong hổ trợ 1 phần nào cho bạn

            const init = {
                username: '',
                permission: null,
                avatar: null,
                ten_dang_nhap: null,
                voteComments: {
                    upVoteComments: [],
                    downVoteComments: []
                },
                votePosts:{
                    upVotePosts: [],
                    downVotePosts: []
                },
                clickThongBao: 0,
                thongBao:[]
            }
            const Login = (state = init, action) => {
                switch(action.type){
                    case 'CAP_NHAT_THONG_BAO_DA_DOC_X':
                    console.log(action)
                    var id = action.id_thong_bao;
                    state.thongBao = action.thongBao;
                    return Object.assign({}, state);
                    case 'CAP_NHAT_THONG_BAO_X':
                        // console.log('sdasdsadas', action)
                        state.thongBao = action.thongBao;
                        return Object.assign({}, state);
                    case 'DANG_NHAP_X':
                        state = action.user.user
                        // console.log(action.user)
                        return Object.assign({}, state);
                    case 'UP_OR_DOWN_VOTE_COMMENT_X':
                        state.voteComments = action.comment.voteComments;
                        return Object.assign({}, state);
                    case 'UP_OR_DOWN_VOTE_POST_X':
                        state.votePosts = action.vote.votePosts;
                        return Object.assign({}, state);
                    case 'CHUA_DANG_NHAP':
                        state = {
                            error: "Bạn chưa đăng nhập",
                            code: "1001"
                        }
                        return state;
                    case 'DANG_XUAT_X':
                        // alert('ok');
                        console.log(action)
                        // if(action.data)
                        // return init;
                        // else return state;
                        // state.voteComments = action.comment.voteComments;
                        return Object.assign({username: null}, init);
                    default:
                        return state;
                }
            }
            
            export default Login;
            

            Đam mê công nghệ
            Không biết nhiều nhưng cũng muốn đóng góp

            1 Reply Last reply Reply Quote 0
            • Q
              Quy Tran last edited by

              @Hai-Dang-Vu
              Bạn thử chỉnh lại code cho case FETCHING_START

              newState = Object.assign({}, state, {
               isFetching: true,
               text: ....
              }
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              $(document).ready(function () { app.coldLoad(); }); }