MOCKSTACKS
EN
Questions And Answers

More Tutorials









React with Redux


Redux has come to be the status quo for managing application-level state on the front-end these days, and those who work on "large-scale applications" often swear by it. This topic covers why and how you should use the state management library, Redux, in your React applications.

Using Connect


Create a Redux store with createStore.

import { createStore } from 'redux'
import todoApp from './reducers'
let store = createStore(todoApp, { inistialStateVariable: "derp"})


Use connect to connect component to Redux store and pull props from store to component.

import { connect } from 'react-redux'
const VisibleTodoList = connect(
 mapStateToProps,
 mapDispatchToProps
)(TodoList)
export default VisibleTodoList
Define actions that allow your components to send messages to the Redux store.
/*
 * action types
 */
export const ADD_TODO = 'ADD_TODO'
export function addTodo(text) {
 return { type: ADD_TODO, text }
}


Handle these messages and create a new state for the store in reducer functions.

function todoApp(state = initialState, action) {
 switch (action.type) {
 case SET_VISIBILITY_FILTER:
 return Object.assign({}, state, {
 visibilityFilter: action.filter
 })
 default:
 return state
 }
}


Conclusion

In this page (written and validated by ) you learned about React with Redux . What's Next? If you are interested in completing React tutorial, we encourage you simply to start here: React Tutorial.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.