JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.3.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.3.2/umd/react-dom.development.js"></script>
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
Babel + JSX
class Test extends React.Component {
static getDerivedStateFromProps({ text }) {
// This seems pointless but not all text that is typed comes back as props
// only some updates are propagated to the redux store
// this is so that people can type invalid things, but only valid input is saved
if (text) {
// Unexpectedly this fires after setState is called
// If we return text here it will take precedence
// over the value passed in setState
return { text }
}
return null
}
constructor(props) {
super(props)
this.state = {
text: props.text
}
}
changeLang(newText) {
this.setState({ text: newText })
}
render() {
return (<div>
<input onChange={({ target }) => this.changeLang(target.value)} value={this.state.text} />
</div>);
}
}
ReactDOM.render(<Test text="hello " />, document.querySelector("#app"));