Trigger onchange when adding/removing an option on a select (ReactJs)

I want to trigger a function when i add a new option in a select. This is the code in the select

<select name="projects" id="projects" onChange={handleChange}>
              {Object.keys(items.projects).length !== 0 ? 
     => {return<option>{i}</option>})
              : <option>Create new project</option> }

Function where i trigger the adding of option in select

function handleAdd(event,name,desc){
        itemDispatch({type:'ADD_PROJECT', name, desc});
        document.getElementById("projects").dispatchEvent(new Event ('change'));

The handleChange function

 function handleChange(){

Read more here:

Content Attribution

This content was originally published by sizzlingseal at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: