Created
April 3, 2019 11:41
-
-
Save kjosavik/d1502ea25a92d5134f34b2bf77b8f109 to your computer and use it in GitHub Desktop.
A simple app with an input field and submit button that displays the inputted text to a div. This one does not use styled-components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import '../assets/css/withoutStyledComponents.css' | |
export default class WithoutStyledComponents extends React.Component{ | |
constructor(props){ | |
const defaultOutput = "Change me..."; | |
super(props); | |
this.state={ | |
value: defaultOutput, | |
displayedValue: defaultOutput, | |
} | |
} | |
updateValue = (e) => { | |
e.preventDefault(); | |
this.setState({value: e.target.value}); | |
} | |
updateDisplayedValue = () => { | |
this.setState({displayedValue: this.state.value}); | |
} | |
render(){ | |
return( | |
<div id="main"> | |
<div id="output-area"> | |
<div id="output">{this.state.displayedValue}</div> | |
</div> | |
<div id="input-area"> | |
<input id="input" onChange={this.updateValue} value={this.state.value}/> | |
<button id="button" onClick={this.updateDisplayedValue}>Update output</button> | |
</div> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment