React and Redux

 

- Abhinay Bathina
- Kaushik Rishi

Indian Institute of Information Technology, Sri City

Redux

  • Central data store for all app data
  • Any component can access data from it
  • Makes state management very easy

Redux

Redux

Redux

Redux

Store

connect()

Component

Higher Order Component

Redux

Redux

Let's consider this example

Redux

import { connect } from 'react-redux'

const TodoItem = ({ todo, destroyTodo }) => {
  return (
    <div>
      {todo.text}
      <span onClick={destroyTodo}> x </span>
    </div>
  )
}

const mapStateToProps = state => {
  return {
    todo: state.todos[0]
  }
}

const mapDispatchToProps = dispatch => {
  return {
    destroyTodo: () =>
      dispatch({
        type: 'DESTROY_TODO'
      })
  }
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(TodoItem)

Redux

References

THANK YOU

React and Redux

By Kaushik Rishi

React and Redux

  • 13