Skip to content

Instantly share code, notes, and snippets.

@tarang9211

tarang9211/app.js

Last active Sep 10, 2018
Embed
What would you like to do?
import React, { Component } from 'react';
class App extends Component {
state = {
questions: this.props.questions,
showState: false,
};
handleChange = id => e => {
const { questions } = this.state;
const selectedQuestion = questions.find(question => question.id === id);
selectedQuestion.value = e.target.value;
questions[id] = selectedQuestion;
this.setState({ questions });
};
handleSubmit = e => {
e.preventDefault();
this.setState({ showState: true });
};
render() {
return (
<div className='App'>
<form>
{questions.map(({ id, question, value }) => {
return (
<div key={id}>
<input
type="text"
name={question}
value={value}
placeholder={question}
onChange={this.handleChange(id)}
/>
</div>
);
})}
<button type="submit">Submit</button>
</form>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment