Last active
April 18, 2024 19:18
-
-
Save cmdcolin/de4027fc90c6a55a2a66a130d640356a 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
function TranscriptSelector() { | |
const [error, setError] = useState(); | |
const [transcripts, setTranscripts] = useState(); | |
const [selection, setSelection] = useState(); | |
useEffect(() => { | |
async () => { | |
try { | |
const result = await loadTranscripts(); // imagine this just returned a list of strings | |
setTranscripts(result); | |
setSelection(result[0]); // set the initial selection to the first transcript | |
} catch (e) { | |
setError(e); | |
} | |
}; | |
}); | |
return error ? ( | |
<div style={{ color: "red" }}>{`${error}`!!!}</div> | |
) : ( | |
<TranscriptSelector2 | |
selection={selection} | |
options={transcripts} | |
onChange={sel => setSelection(sel)} | |
/> | |
); | |
} | |
function TranscriptSelector2({ options, selection, onChange }) { | |
return ( | |
<select | |
value={mySelection} | |
onChange={event => setMySelection(event.target.value)} | |
> | |
{opts.map(o => ( | |
<option key={o} value={o}> | |
{o} | |
</option> | |
))} | |
</select> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment