import React, { Component } from "react";
export default class FontChanger extends Component{
constructor(props){
super(props);
this.state ={
selectedFont: "",
currentFont: "",
};
this.handleFontChange = this.handleFontChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleFontChange(event){
this.setState({
currentFont: event.target.selectedFont,
selectedFont: this.state.value
});
}
handleSubmit(event) {
event.preventDefault();
this.setState({ currentFont: this.state.selectedFont });
}
render() {
return(
<div>
<form onSubmit={this.handleSubmit}>
<h1 style={{fontFamily: this.state.currentFont }}>Yuh Yeet</h1>
<select onChange={this.handleFontChange}>
<option value="Anton">Anton</option>
<option value="Calistoga">Calistoga</option>
<option value="Fira Sans">Fira Sans</option>
<option value="Noto Serif">Noto Serif</option>
<option value="Quicksand">Quicksand</option>
<option value="Ubuntu">Ubuntu</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Titillium Web">Titillium Web</option>
</select>
<button type="submit"> Change </button>
</form>
</div>
)
}
}
I'm having trouble changing the inline style of the h1 tag with a font selected from my dropdown menu. I've imported all fonts into my index.html from Google Fonts, so that shouldn't be an issue. Could it be an error in how I'm using setState or accessing the state values?