Created
June 2, 2018 18:55
-
-
Save alonn24/f317c267e3367324b5133712a151d803 to your computer and use it in GitHub Desktop.
react wrapper for a word counter custom component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './word-count/word-count'; | |
import { observable } from 'mobx'; | |
import { observer } from 'mobx-react'; | |
import * as React from 'react'; | |
import * as ReactDOM from 'react-dom'; | |
declare global { | |
namespace JSX { | |
interface IntrinsicElements { | |
'word-count': any | |
} | |
} | |
} | |
class AppState { | |
@observable wordCount = 'word count'; | |
} | |
@observer | |
class ReactWordCount extends React.Component<any, any> { | |
updateProperty = (event) => { | |
this.props.appState.wordCount = event.target.value; | |
}; | |
render() { | |
return ( | |
<div> | |
<div className='title'>Web Components</div> | |
<input value={ this.props.appState.wordCount } onChange={this.updateProperty}/> | |
<word-count text={ this.props.appState.wordCount }> | |
<span slot='title'>Word Count:</span> | |
Light DOM Content | |
</word-count> | |
</div> | |
); | |
} | |
} | |
const appState = new AppState(); | |
ReactDOM.render( | |
<ReactWordCount appState={ appState }></ReactWordCount>, | |
document.getElementById('root') | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment