<div id="app"></div>
@import 'https://fonts.googleapis.com/css?family=Share+Tech+Mono';

@import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(#28a9dd, #0d4e77);
  font-family: "Share Tech Mono", monospace;
  font-size: 2rem;
}

.card {
    position: relative;
    backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
    padding:2vw;
    box-sizing: border-box;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    transition: .3s ease;
    margin: 3vw;
}

h1 {
  position: relative;
  z-index: 1;
  border-left: 5px solid #ed2553;
  margin: 0 0 3vh -2vw;
  padding: 10px 0 10px 2vw;
  color: #ed2553;
  font-size: 32px;
  font-weight: 600;
  text-transform: uppercase;
}

p {
  font-family: "Share Tech Mono", monospace;
  margin: 1em 0;
  text-align: center;
}

input[type="text"]{
	padding: 15px;
	border: 1px solid #ccc;
	border-radius: 3px;
	margin-bottom: 10px;
	width: 100%;
	box-sizing: border-box;
	font-family: "Share Tech Mono", monospace;
	color: #2C3E50;
	font-size: 16px;
}
View Compiled
var localStorageMixin = {
    getInitialState: function(){
        return {
            value: localStorage.getItem('userName') || '@大漠'
        }
    },
    setLocalStorage: function(val) {
        localStorage.setItem('userName', val)
    }
}

var App = React.createClass({
    mixins: [localStorageMixin],
    componentDidUpdate: function(){
        this.setLocalStorage(this.state.value)
    },
    onChange: function(e) {
        this.setState({
            value: e.target.value
        })
    },
    render() {
      return (
        <div className="card">
            <h1>使用React Mixin和createClass创建组件</h1>
            <input 
                type="text"
                value={this.state.value}
                onChange={this.onChange}
            />
            <p>Hello, {this.state.value} (^_^)!!!</p>
        </div>
      )
    } 
})

const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react-dom.min.js