React

PUBLIC - DO NOT DELETE

by morphcast

HTML

<!-- import MorphCast SDK libs -->
<script src="https://sdk.morphcast.com/mphtools/v1.0/mphtools.js"></script>
<script src="https://ai-sdk.morphcast.com/v1.16/ai-sdk.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;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

.done {
  color: rgba(0, 0, 0, 0.3);
  text-decoration: line-through;
}

input {
  margin-right: 5px;
}

React

/* global CY */

// SDK GETTING STARTED SNIPPET
// ( see https://ai-sdk.morphcast.com/latest/index.html )
CY.loader()
	//.licenseKey('insert-here-your-license-key')
  .addModule(CY.modules().FACE_EMOTION.name)
  .load()
  .then(({ start, stop }) => start());
///

class SampleApp extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
    	emo : ""
    }
  }
  
  componentDidMount() {
     window.addEventListener(CY.modules().FACE_EMOTION.eventName, (evt) => {
        this.setState({emo: evt.detail.output.dominantEmotion});
 		 });
  }
  
  render() {
    return (
      <div>
        Detected dominant emotion: {this.state.emo}
      </div>
    )
  }
}

ReactDOM.render(<SampleApp />, document.querySelector("#app"))