I have done same concept in my project but used for different purpose
In my project, There is a card element with dropdown element. In card media, I used random image loader([lorempixel.com][1]) so i am changing the random image category in link http://lorempixel.com/500/400/[category] (Ex: http://lorempixel.com/500/400/nature) so it will update link and shows different category image on change of dropdown.
Below is how i updating the link on change of dropdown
onChange event is calling handleChange function
onChange={this.handleChange}
In handleChange function, I am updating the state
this.setState({
text: event.nativeEvent.target.innerText,
value: value
});
Here, I am updating the state
<img src={"http://lorempixel.com/500/400/"+this.state.text} />
Here is the code i was written, Hope it will helps you. If u want any thing let me know
import React from "react";
import Card from "material-ui/Card";
import CardActions from "material-ui/Card/CardActions";
import CardTitle from "material-ui/Card/CardTitle";
import CardHeader from "material-ui/Card/CardHeader";
import CardMedia from "material-ui/Card/CardMedia";
import CardText from "material-ui/Card/CardText";
import Drawer from "material-ui/Drawer";
import DropDownMenu from "material-ui/DropDownMenu";
import IconMenu from "material-ui/IconMenu";
import IconButton from "material-ui/IconButton";
import Menu from "material-ui/Menu";
import MenuItem from "material-ui/MenuItem";
import MoreVertIcon from "material-ui/svg-icons/navigation/more-vert";
const styles = {
margin: {
margin: "20px 300px"
},
float: {
float: "right"
},
};
class About extends React.Component {
constructor(props, context) {
super(props, context);
this.handleChange = this.handleChange.bind(this);
this.state = {
text: "nature",
value: 3
};
}
handleChange(event, index, value){
this.setState({
text: event.nativeEvent.target.innerText,
value: value
});
}
render(){
const IconMenuRight = (
<DropDownMenu
style={styles.float}
value={this.state.value}
iconButtonElement={<IconButton><MoreVertIcon /></IconButton>}
onChange={this.handleChange}>
<MenuItem value={1}>sports</MenuItem>
<MenuItem value={2} primaryText="city" />
<MenuItem value={3} primaryText="nature" />
<MenuItem value={4} primaryText="animals" />
<MenuItem value={5} primaryText="abstract" />
<MenuItem value={6} primaryText="cats" />
<MenuItem value={7} primaryText="food" />
<MenuItem value={8} primaryText="nightlife" />
<MenuItem value={9} primaryText="people" />
<MenuItem value={10} primaryText="technics" />
<MenuItem value={11} primaryText="transport" />
</DropDownMenu>
)
return(
<Card style={styles.margin}>
<CardHeader
avatar="http://lorempixel.com/400/200/people"
title="http://lorempixel.com/"
subtitle="A random image loader. Change the drop down value to see the diffent category image.">
{IconMenuRight}
</CardHeader>
<CardMedia>
<img src={"http://lorempixel.com/500/400/"+this.state.text} />
</CardMedia>
<CardTitle
title={"React js"}
subtitle="React is the entry point to the React library. If you're using one of the prebuilt packages it's available as a global; if you're using CommonJS modules you can require() it."/>
<CardText>
Webdesign or Print. Its simple and absolutely free! Just put the custom url in your code like this:
to get your FPO / dummy image.
</CardText>
</Card>
)
}
}
export default About;