0

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.

1
  • There are no "pages" in React. You can either set the data as a prop and pass it down my instantiating 'Tournaments' in the 'New' component, or you can use Redux. Commented Mar 12, 2018 at 15:09

1 Answer 1

-1

Simple.Pass the data as array from the component where submit action is called and have a const to iterate the map in the component where you want to render the Data.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.