React Redux无法与Next.js和NodeJS一起正常工作

JavaScript React.js

小胖

2020-03-23

通过遵循此示例我正在使用带有Redux的Next.js的应用程序,这是其中的一部分store.js

// REDUCERS
const authReducer = (state = null, action) => {
    switch (action.type){
        case actionTypes.FETCH_USER:
            return action.payload || false;
        default:
            return state;
    }
}

export const rootReducer = combineReducers({
    user: authReducer,
    form: reduxForm,
});

// ACTIONS
export const fetchUser = () => {
    return (dispatch) => {
        axios.get('/api/current_user')
            .then(res => dispatch({
                type: actionTypes.FETCH_USER, 
                payload: res.data
            }));
    };
};

export const submitLogin = (values) => async dispacth => {
    const res = await axios.post('/api/login', values);

    // Router.push('/');
    // console.log(res)

    dispacth({ type: actionTypes.SUBMIT_LOGIN, payload: res.data });
};

和客户端,例如 header

function mapStateToProps (state) {
    const { user } = state
    return { user }
}

export default connect(mapStateToProps)(Header)

当我console.log('############=>', this.props.user);的道具和我没有登录时,它显示为空,但显示一些额外的数据,例如下面的屏幕截图

在此处输入图片说明

但是当我登录并console.log('############=>', this.props.user);显示正确的数据时,没有额外的数据,例如下图

在此处输入图片说明

我做错了什么?请帮我。谢谢

第3124篇《React Redux无法与Next.js和NodeJS一起正常工作》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android