I am trying to fill the dropdown with the data from the given array 'options' but I'm running into an error where it cannot read property appendChild of null.
If I use 'document.getElementByClassName' instead of document.getElementById for 'select', I run into an error where 'select.appendChild is not a function'
works on codepen but does not work in my react function. https://codepen.io/michaellee212/pen/LYpGgrm
I can't figure out why this problem happens
code:
export default function ComposeEmailForm({ handleCompose, template_titles }) {
var options = ['1', '2', '3', '4', '5'];
var select = document.getElementById('template-select');
for (var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement('option');
el.text = opt;
el.value = opt;
console.log(el);
select.appendChild(el);
}
return (
<select id='template-select'>
<option>----</option>
</select>
)