简体   繁体   English

在redux中,reducer改变状态后会发生什么?

[英]In redux, what happens after reducer change the state?

I am reading the source code of a react app , which implement OKTA user management API.我正在阅读react app的源代码,它实现了 OKTA 用户管理 API。

One thing that make me confused is how after the state change for example after logIn让我感到困惑的一件事是状态更改后如何,例如在登录

const registration = (state = initialState, action) => {
    switch (action.type) {
        case 'LOGOUT':
            return Object.assign({}, state, {sessionToken: null, error: null});
        case 'LOGIN_ERROR':
            return Object.assign({}, state, {sessionToken: null, error: action.payload});
        case 'LOGIN_SUCCESS':
            return Object.assign({}, state, {sessionToken: action.payload, error: null});
        default:
            return state;
    }
};

I guess login page would be rendered to profile page.我猜登录页面将呈现到个人资料页面。 But here the reducer only connected to store .但是这里的 reducer 只连接到store Then how does this work?那么这是如何工作的呢?

PS: I attached wrong code at first. PS:我一开始附错了代码。

The react-redux plug-in is the glue between redux and react . react-redux插件是reduxreact之间的redux The plug-in subscribes to the store to be called whenever the store state changes.插件订阅要在商店状态改变时调用的商店。 Each time the store changes, react-redux updates all of it's connected components.每次 store 发生变化时, react-redux更新所有连接的组件。 This is done in a way that is optimal as to not update a component if the part of the store that changed is of no interest to that component.这是以最佳方式完成的,如果该组件对更改的存储部分不感兴趣,则不更新该组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM