Created
December 11, 2018 22:11
-
-
Save IllegalSkillsException-active/24770a2f17adce2ec570257a18b92e59 to your computer and use it in GitHub Desktop.
Thinkful React Communication Drills
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
-----surprise.js----- | |
import React from 'react'; | |
import SurpriseButton from './surprise-button'; | |
import SurpriseImage from './surprise-image'; | |
export default class Surprise extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
display: 'button' | |
} | |
} | |
showImage() { | |
this.setState({ | |
display: 'image' | |
}); | |
} | |
render() { | |
if (this.state.display === 'button') { | |
return <SurpriseButton onClick={e => this.showImage()} />; | |
} | |
else if (this.state.display === 'image') { | |
return <SurpriseImage />; | |
} | |
} | |
} | |
-------->rate-calculator.js<-------- | |
import React from 'react'; | |
import NumberInput from './number-input'; | |
import Output from './output'; | |
export default class RateCalculator extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state ={ | |
dayRate:0, | |
hours:0, | |
} | |
this.handleDayRateChange = this.handleDayRateChange.bind(this); | |
this.handleHoursChange = this.handleHoursChange.bind(this); | |
} | |
handleDayRateChange(e){ | |
let dayRate= e.target.value; | |
this.setState({dayRate:dayRate}); | |
} | |
handleHoursChange(e){ | |
let hours = e.target.value; | |
this.setState({hours:hours}); | |
} | |
render() { | |
console.log(this.state); | |
let rate = this.state.dayRate/this.state.hours; | |
return ( | |
<form> | |
<NumberInput handleChange={this.handleDayRateChange} id="day-rate" label="Day rate" min={0} max={5000} /> | |
<NumberInput handleChange={this.handleHoursChange} id="hours" label="Hours" min={1} max={12} /> | |
<Output id="hourly-rate" label="Hourly rate" value={rate.toFixed(2)} | |
/> </form> | |
); | |
} | |
} | |
-------->live-search.js<-------- | |
import React from 'react'; | |
import SearchForm from './search-form'; | |
import CharacterCount from './character-count'; | |
import CharacterList from './character-list'; | |
export default class LiveSearch extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
searchTerm: '' | |
} | |
this.handleSearchChange = this.handleSearchChange.bind(this); | |
} | |
handleSearchChange(term){ | |
this.setState({searchTerm:term}); | |
} | |
render(){ | |
const characters = this.props.characters.filter(character => | |
character.name.includes( | |
this.state.searchTerm | |
) | |
); | |
console.log(characters); | |
console.log(characters.length); | |
return( | |
<div className='live-search'> | |
<SearchForm onChange={this.handleSearchChange} /> | |
<CharacterCount count={characters.length} /> | |
<CharacterList characters={characters} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment