Home » Interview » Redux Interview Questions :: Discussion
  1. What is the purpose of the connect() function in Redux?

    The connect() function is used to connect a React component to the Redux store. It takes two arguments: mapStateToProps and mapDispatchToProps, which are functions that map the state of the store and action creator functions to the props of the component. The connect() function returns a new component that is connected to the Redux store.

    Example:

    import { connect } from 'react-redux';
    import Counter from './Counter';

    function mapStateToProps(state) {
      return { count: state.count };
    }

    export default connect(mapStateToProps)(Counter);


Be The First To Comment