So, I am just trying to get the skeleton working…well idea of the skeleton for the app I want to re try. Now I am trying to update the state from the child component…I think I passed in the state as props correctly, but to be honest im not sure about the actual updating part. the handle change method will capture the input, and then im assuming the submit will set the state name to the input. Essentially it will be where the user can edit the recipe not just the name…but baby steps. of course I only wanted one name to change, but wasnt quite sure in the onsubmit method. Will take any help here
class RecipeBox extends React.Component {
constructor(props) {
super(props);
this.state = {
input:'',
recipeList :
[{
recipe: "Tacos",
directions: "make tacos",
ingredients: ["meat"]
},
{
recipe: "pizza",
directions: "bake",
ingredients: ["dough"]
}]
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}///
handleChange(event) {
this.setState({
input: event.target.value
});
}
handleSubmit(e){
e.prevent.Default
setState({
recipe: input
})
}
render(){
const {input} = this.state;
const ITEMS = this.state.recipeList.map(({directions}) => <li>{directions}</li>)
return(
<div>
<EditList input = {this.state.input}
handleChange = {this.handleChange}
onSubmit = {this.handleSubmit}/>
<ul>
{ITEMS}
</ul>
</div>
)
}
}
class EditList extends React.Component {
constructor(props) {
super(props);
}
render() {
return(
<div>
<input type='text'
value ={this.props.input}
onchange = {this.props.handleChange}
/>
<button onClick={this.props.onSubmit}>Submit</button>
</div>
)
}
}
ReactDOM.render(<RecipeBox />, document.getElementById('app'));