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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <!--
    Demonstrates how ReactJS can be mounted to 
    multiple containers and share the same 
    state with Redux.
-->
<div id="mood-view"></div>
<div id="mood-button"></div>
              
            
!

CSS

              
                html {
    height: 100%
}

body {
    align-items: center;
    display: flex;
    flex-direction: column;
    font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
    height: 100%;
    justify-content: center;
    text-align: center;
}

.Mood__emoji {
    line-height: 4rem;
    font-size: 4rem;
    margin-bottom: .25rem;
}

.Mood__name {
    font-size: 1.75rem;
    margin-bottom: 2rem;
}

.Mood__button {
    background: #eee;
    border: 1px solid #ddd;
    cursor: pointer;
    padding: .5rem 1rem;
    font-size: .75rem;
    margin-bottom: 1rem;
}
              
            
!

JS

              
                const { createStore, applyMiddleware } = Redux;
const { Provider } = ReactRedux;
const { connect } = ReactRedux;
const { combineReducers } = Redux;

// Actions
const SET_MOOD = "SET_MOOD";

function setMood() {
    const moods = [
        { name: "Happy", "emoji": "😀" }, 
        { name: "Angry", "emoji": "😠" },
        { name: "Really Angry", "emoji": "😡" },
        { name: "Sad", "emoji": "🙁" },
        { name: "Really Sad", "emoji": "☚ī¸" },
        { name: "Poop", "emoji": "💩" }
    ];
    
    const mood = moods[Math.floor(Math.random()*moods.length)];

    return { 
        type: SET_MOOD, 
        mood 
    };
}

// Reducer
const initialState = { 
    name: [ "Emoji Placeholder" ], 
    emoji: null
};

function mood(state = initialState, action) {
  switch(action.type) {
    case SET_MOOD:
      return action.mood;
      
    default:
      return state;      
  }
}

// Store
const App = combineReducers({ mood });
const store = createStore(App);

// Our Pure Components
function MoodView({ mood }) {
    return (
        <div className="Mood">
            <div className="Mood__emoji">{ mood.emoji }</div>
            <div className="Mood__name">{ mood.name }</div>
        </div>
    )
};
                    
function MoodButton({ onButtonClick, mood }) {
    return (
        <div className="MoodButton">
            <button className="Mood__button" onClick={ onButtonClick }>
                Random Mood - { mood.name }
            </button>
        </div>
    )
};

// Connect our state and actions to our components
function mapStateToProps(state, ownProps) {
    return {
        mood: state.mood
    }
} 

function mapDispatchToProps(dispatch) {
    return {
        onButtonClick: () => dispatch(setMood())
    }
}

const MoodViewConnected = connect(mapStateToProps, mapDispatchToProps)(MoodView)
const MoodButtonConnected = connect(mapStateToProps, mapDispatchToProps)(MoodButton)

// Render each connected component separatly. 
// Both components share the same state.
React.render(
    <Provider store={ store }>
        <MoodViewConnected />
    </Provider>,
    document.getElementById('mood-view')
);

React.render(
    <Provider store={ store }>
        <MoodButtonConnected />
    </Provider>,
    document.getElementById('mood-button')
);
              
            
!
999px

Console