Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div>
  <h1>Extract state logic to Redux</h1>
  <blockquote cite="https://www.freecodecamp.org/learn/front-end-libraries/react-and-redux/extract-state-logic-to-redux">Now that you finished the React component, you need to move the logic it's performing locally in its state into Redux. This is the first step to connect the simple React app to Redux. The only functionality your app has is to add new messages from the user to an unordered list. The example is simple in order to demonstrate how React and Redux work together.<br>
First, define an action type ADD and set it to a const ADD. Next, define an action creator addMessage() which creates the action to add a message. You'll need to pass a message to this action creator and include the message in the returned action.<br>
Then create a reducer called messageReducer() that handles the state for the messages. The initial state should equal an empty array. This reducer should add a message to the array of messages held in state, or return the current state. Finally, create your Redux store and pass it the reducer.
</blockquote>
  <pre><code>
// Define ADD, addMessage(), messageReducer(), and store here:
const ADD = "ADD";
const addMessage = (message) =>
{return {
  type: ADD, 
  message: message}};
let messageReducer = ((state = [], action) => 
{
  switch(action.type) { 
case "ADD": 
return [...state, action.message];
default:
return state;}
}
);
let store = Redux.createStore(messageReducer);
</code></pre>
<p>Create an action type and set it to a constant of ADD. This does not mean assign a variable to the string "ADD." it means to create a variable that is a constant with the type property of "ADD.</p>
<pre><code>
const ADD = {type: "ADD"};
let addMessage = (message) => {return
{message: "ADD"}
};
let messageReducer = ((state = [], action) => 
{
  switch(action.type) { 
case "ADD": 
return [...state, action.ADD];
default:
return state;}
}
);
</code></pre>
<p>My action only has type. Is message needed?<br>
Assignment to the string "ADD" is literal.<br>
I do not know how to output the desired action in the action creator since I do not know what it would look like. How do I create the action creator?<br>
The action creator is describing the new state. This is a new message. I guess it is acceptable to use the same name of the property as the value as in message: message.<br>
I see action.something and think I am seeing action.property for the first time.<br>
You have seen this. Other projects are available in you snippets. This says ".message" which could mean the action that is for the message property.</p>
</div>
<div id="root">
    <!-- This element's contents will be replaced with your component. -->
</div>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console