Redux two deadly key points encountered during use

Source: Internet
Author: User

First, in Reducer, the returned state must be a completely new object , otherwise redux will not execute the listening method, because Redux will assume that state has not been updated and there is no need to re-render the view.

Examples of problems that occur:

Const user= (state={name= ", age=0},action) =     {switch(            action.type) {  case ' Change_name ':                  state.name= ' Zhangsan ';   modifies the name return state in the original object                  ;               default :              return State ;      }      }

Yes, this is the case, even if the name value of the old state is modified, but Redux does not think the state has changed, I did not see the source code (rookie, to study for a long time), but the guess is, redux to each state attaches a key value, so, is to decide whether to re-render the view by judging key.

Second, Redux Combinereducers method, False with Reducer1 (signUp) and Reducer2 (SignIn), two reducer have action type (' Change_username '), You will find that in one of the view changes username, and the other username will follow,

In other words, even in different reducer, it is best not to have the same action type, otherwise there will be dirty data generated.

Redux two deadly key points encountered during use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.