I'm mapping over an array of objects and using the name in dropdown selection w/ semantic-ui-react.
I have some mock data
mock.onGet("/dataschemas").reply(200, {
data: [
{
id: "2147483599",
selfUri: "/dataschemas/2147483599",
name: "Book Catalog"
},
{
id: "2147483600",
selfUri: "/dataschemas/2147483600",
name: "Business Articles"
}
]
});
in cDM I'm updating state with the object as dataschemas
async componentDidMount() {
await this.getSchemas();
}
getSchemas = async () => {
try {
const { data } = await axios.get("/dataschemas");
console.log(data);
const dataschemas = data.data;
this.setState({ dataschemas: dataschemas });
console.log("This is the dataschema list:", dataschemas);
} catch (error) {
console.error(Error(`Error fetching results list: ${error.message}`));
}
};
My change handler function looks like this:
handleSchemaChange = (e, { value }) => this.setState({ name: value });
Then in render I'm using the <Dropdown> component
render() {
const { dataschemas } = this.state;
return (
<div>
<div>
<label>Select a dataschema: </label>
<Dropdown
placeholder="Select data schema"
clearable
fluid
selection
multiple={true}
options={dataschemas}
header="PLEASE SELECT A DATASCHEMA"
value={dataschemas.filter(({ name }) => name === this.state.name)}
onChange={this.handleSchemaChange}
/>
</div>
</div>
);
}
I can't get the dataschema names to show in the dropdown or get label to update when a selection is made. I don't know if I'm missing a prop or not updating the state correctly, any ideas?
Codesandbox here