I've been learning react and trying to get a user input from one page to another. I've tried some different things already like refs and props and redux but I just can't figure it out. My goal is that when data is inserted to the text box and submit is clicked that I could show a list of these entries on the second page.
This is the page for input
import React, { Component } from "react";
class New extends Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert(this.state.value + ' successfully created');
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label for="tournyName">Tournament name:</label>
<input type="text" class="form-control" id="tournyName" value= {this.state.value} onChange={this.handleChange}></input>
<button type="submit" value="Submit" class="btn btn-primary">Create tournament</button>
</form>
);
}
}
export default New;
Goal is to have user inputs in this list
import React, { Component } from "react";
class Tournaments extends Component {
render() {
return (
<h2>List of tournaments:</h2><br></br>
<ul>
<li>User created tournament name here</li>
</ul>
);
}
}
export default Tournaments;
Thanks for any help in advance.