-
-
Save jlengstorf/dfe85362ee214ea6117791cf6afe8dbc to your computer and use it in GitHub Desktop.
this is not real code, but it's pretty similar to what I was trying when I got frustrated with trying to write React hooked up to a non-React lib
This file contains hidden or 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
| // external thing that sends/receives MIDI | |
| const box = new Box(); | |
| export function MyComponent() { | |
| const [code, setCode] = useState(''); | |
| useEffect(() => { | |
| function handleKeyPress(id, key) { | |
| setState((curr) => curr += key); | |
| } | |
| async function handleEnterKey(id) { | |
| // hits an external DB | |
| // for some reason this was always showing code as an empty string | |
| const isValid = await checkForValidCode(code); | |
| if (isValid) { | |
| box.setSuccessOn(id); | |
| } else { | |
| box.setFailureOn(id); | |
| } | |
| setCode(''); | |
| } | |
| box.onKey(handleKeyPress); | |
| box.onEnter(handleEnterKey); | |
| }, []); | |
| // the UI is also subscribed to some other stuff to do with code claim status, etc. | |
| return ( | |
| <p>{code}</p> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment