I am new to react and office-ui-fabric and have been having issues understanding how to add a dropdown to useEffect. The user selects options from the dropdown and i need useEffects to monitor the value selected to another user so that i can send the value selected to another function.
const options: IDropdownOption[] = [
{ key: "A", text: "A", itemType: DropdownMenuItemType.Header },
{ key: "B", text: "B" },
{ key: "C", text: "C" }
];
const [selectedItem, setOption] = React.useState("");
React.useEffect(() => {
window.addEventListener("message", ev => {
switch (ev.data.command) {
case "selectedItem": {
console.log(`Got message`);
setOption(ev.data.payload);
break;
}
}
});
}, []);
let test = () => {
console.log("Test");
vscode.postMessage({
command: "setOption",
text: "select option"
});
window.console.log(`Sent message.`);
};
return (
<div>
<Stack>
<Stack.Item grow>
<Label style={{ color: "white" }}>Select Option</Label>
<Dropdown
placeholder="Select option"
options={options}
styles={dropdownStyles}
selectedKey={selectedItem}
onChanged={selectedOption => {
setOption(selectedOption.text);
console.log(selectedOption.text);
test;
}}
/>
</Stack.Item>
</Stack>
`enter code here`
</div>
);
Currently i don't see the log "Test" inside test() or any of the logs "Got message" etc which means test is not getting triggered. Is this the right way ?or should i have an onClick like functionality for test ?