This tutorial will show how to write a ''Hello Server'' application using ''React'' and ''Vaandroid''
Writing the application in React allows:
Client-Side Benefits
Server Side Benefits
This template pulls down the required libraries from CDN, and renders a component in a target div. Our source code is written in JSX and is rendered on-the-fly in the client browser.
{CODE(wrap="0" colors="text/javascript")} <!DOCTYPE html> <html lang="en">
</html> {CODE}
{CODE(wrap="0" colors="js")} class Form extends React.Component { constructor() { super(); this.state = { name: '' }; }
render() {
return <div>Please enter your name and press <em>Submit</em>.<br />
<input placeholder="Enter your name here" on<x>change={e=>this.handleName(e)}
value={this.state.name}/>
<button on<x>click={e=>this.handleSubmit()}>Submit</button>
</div>
}
handleName(e) {
this.setState({name: e.target.value});
}
handleSubmit() {
al<x>ert('Hello ' + this.state.name);
}
}
{CODE}
Send the code to the server by calling vaandroid.send(...)
{CODE(wrap="0")}handleSubmit() { vaandroid.send('Hello ' + this.state.name); }{CODE}
Subscribe to the server's response by overriding vaandroid.receive(...)
{CODE(wrap="0")}constructor() { super(); this.state = { name: '', caption: '' }; vaandroid.receive = function (message) { this.setState({caption: message}); }.bind(this); }{CODE}