Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 19 additions & 38 deletions src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,30 @@ You may obtain a copy of the License at
See the License for the specific language governing permissions and
limitations under the License.*/

import React, { Component } from 'react'
import PropTypes from 'prop-types'

class Input extends Component {
constructor (props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleResponse = this.handleResponse.bind(this);
}

//Callbacks for when user input changes or 'search' is clicked
handleChange(e) {
const { handleChange } = this.props;
handleChange(e);
}

handleKeyPress(target) {
const { handleKeyPress } = this.props;
handleKeyPress(target);
}

handleResponse() {
const { handleResponse, input } = this.props;
handleResponse(input);
}

render() {
const { input } = this.props;
return (
<div className="set">
<input type="text" className="input" placeholder="Enter movie..." value={input} onChange={this.handleChange} onKeyPress={this.handleKeyPress}/>
<button className="button" onClick={this.handleResponse}>Search</button>
</div>
);
}
}
import React from 'react';
import PropTypes from 'prop-types';

const Input = ({ input, handleChange, handleKeyPress, handleResponse }) => (
<div className="set">
<input
type="text"
className="input"
placeholder="Enter movie..."
value={input}
onChange={handleChange}
onKeyPress={handleKeyPress}
/>
<button className="button" onClick={handleResponse}>
Search
</button>
</div>
);

Input.PropTypes = {
input: PropTypes.string,
handleChange: PropTypes.func,
handleKeyPress: PropTypes.func,
handleResponse: PropTypes.func,
}
};

export default Input;