Last active
July 16, 2019 05:00
-
-
Save cruelmelody/fc5a1eb6d34118b76d7c273c813a0ec2 to your computer and use it in GitHub Desktop.
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 React, { Component } from "react"; | |
import BeadCodes from "./data/beadcodes.json"; | |
// import { navigate } from "gatsby" | |
class IndexPage extends Component { | |
state = { | |
barcodeReceiptNo: "" | |
} | |
handleInputChange = event => { | |
const target = event.target | |
const value = target.value | |
const name = target.name | |
this.setState({ | |
[name]: value | |
}); | |
} | |
handleSubmit = event => { | |
event.preventDefault(); | |
alert(`Your barcode number is ${this.state.barcodeReceiptNo}.`); | |
} | |
render () { | |
return ( | |
<> | |
<form className="submitForm" onSubmit={this.handleSubmit}> | |
<input | |
type="text" | |
name="barcodeReceiptNo" | |
value={this.state.barcodeReceiptNo} | |
onChange={this.handleInputChange} | |
/> | |
<button type="submit">Submit</button> | |
</form> | |
<div> | |
{BeadCodes.map((beadCode, index) => { | |
return <h3>{beadCode.code}</h3> | |
})} | |
if ({this.state.barcodeReceiptNo} === {beadCode.code}) { | |
alert("It's a match!") | |
} else { | |
alert("Unlucky.") | |
} | |
</div> | |
</> | |
); | |
} | |
} | |
export default IndexPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment