freeCodeCamp/guide/english/certifications/front-end-libraries/react-and-redux/extract-state-logic-to-redux/index.md

38 lines
1.0 KiB
Markdown

---
title: Extract State Logic to Redux
---
## Extract State Logic to Redux
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/front-end-libraries/react-and-redux/extract-state-logic-to-redux/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
Suggested solution:
```javascript
const ADD = 'ADD';
function addMessage(message) {
return {
type: ADD,
message: message
};
};
function messageReducer (previousState, action) {
return [...previousState, action.message];
}
let store = {
state: [],
getState: () => store.state,
dispatch: (action) => {
if (action.type === ADD) {
store.state = messageReducer(store.state, action);
}
}
};
```