What's the difference between react-redux @ connect () and connect () (App)?

@ connect in

react-redux, why can you get the properties in the object directly, while connect (mapStateToProps, mapDispatchToProps) (App) has to get the properties in the object manually? For example:

const initialState = {
    isAuth: false,
    username: "ok"
}

export function auth(state=initialState, action){
    ...
}

@connect(
    state => state.auth
)

class App extends Component{
    render(){
        return(
            {this.props.isAuth ? "<button></button>" : ""}
            ...
        )
    }
}

you can get isAuth directly by using the decorator here.

but change it to mapStateToProps to get isAuth , you have to write it this way:

const mapStateToProps = state => {
    return{
        isAuth: state.auth.isAuth
    }
}

isAuth,

const mapStateToProps = state => {
    return{
        auth: state.auth
    }
}
this.props.auth.isAuthisAuth

the question is what @ connect has done to the object auth so that we can get the isAuth? without writing isAuth: state.auth.isAuth .

Apr.07,2021

@connect(
    state => state.auth
)

@ connect accepts a function as an argument and unfolds the return value object of this function to the component, that is, props as the component

Menu