Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Last active April 18, 2024 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmdcolin/de4027fc90c6a55a2a66a130d640356a to your computer and use it in GitHub Desktop.
Save cmdcolin/de4027fc90c6a55a2a66a130d640356a to your computer and use it in GitHub Desktop.
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