我的数据存在于reducer中,但无法进入mapStateToProps

减速器-

const INITIAL_STATE ={
    user: null,
    isAuth: false,
    isAuthResolved: false
}
const auth = (state=INITIAL_STATE, action)=>{
switch(action.type){
    case 'SET_AUTH_USER': 
    console.log('reducer',action.user)
    return {user: action.user, isAuthResolved: true, isAuth:!!action.user}
    default:
         return state
}
}

export default auth

我要访问数据的地方-

import { connect } from 'react-redux'

class ServiceApp extends Component {

    renderApplication = (auth) => 
        <React.Fragment>
            <Navbar auth={auth} />
            <Navbar auth={auth} id='navbar-clone'/>
            <Sidebar/>
            <Routes/>
        </React.Fragment>


    render() {
        const {auth} = this.props
        console.log('Props', this.props)
        return this.renderApplication(auth)

    }
}
const mapStateToProps = state =>  {
console.log('State', state)
    return{ 
    auth: state.auth    
}    
}

export default connect(mapStateToProps)(ServiceApp) 

I am not getting the issue Please Resolve it as Soon as possible. Here, Data is perfectly there in Reducer, But in state it's not thereenter image description here

评论
  • qfugit
    qfugit 回复

    Your state is not having the auth object . you need to modify the state like below

    const INITIAL_STATE ={
    auth :{
        user: null,
        isAuth: false,
        isAuthResolved: false
    }
    }