przekazanie obiektu do funkcji

0

Robię cos w stylu historii i chciałbym po kliknieciu dodaj dodac do tablicy obiekt. Mam 2 inputy:

 <input
              value={this.state.X}
              onChange={e => this.setState({
                X: e.target.value
              })}
            />
            <input
              value={this.state.Y}
              onChange={e => this.setState({
                Y: e.target.value
              })}
            />

Mam tez mechanizm historii

state = {
    newItems: [],
    elements: [],
    history: [],
  currentHistoryIndex: 0
}
  
 handleOnHistoryPush = () => {
    this.setState({ history: ([...this.state.history, this.state.elements]) });
    this.setState({ elements: ([]) });
  };
  // dodajemy kolejny element do aktualnych elementów
  appendElement = (value, value2) => this.setState({ elements: ([...this.state.elements, value, value2]) });

render(){
return(
 <div>
            Wpisy<br />
            <button onClick={() => this.appendElement(this.state.Name, this.state.Description)}>Dodaj</button>
            <button onClick={this.handleOnHistoryPush}>Zapisz</button>
            <ul>
              {this.state.elements.map(element => (
                <li>{element}</li>

              ))}
            </ul>
          </div>
          <div>
            Historia<br />
            <select onChange={event => this.setState({ currentHistoryIndex: event.currentTarget.value })}>
              {
                this.state.history.map((_, index) => <option key={index} value={index}>{index}</option>)
              }
            </select>
            {this.state.history[this.state.currentHistoryIndex] && (
              <ul>
                {this.state.history[this.state.currentHistoryIndex].map(historyRecord => <li>{historyRecord}</li>)}
              </ul>
            )}
          </div>
        </div>
)
}

I na razie dodaje oddzielnie 2 wartosci a chcialbym je jako obiekt dodac do tablicy, prosze o pomoc

1

Jeżeli dobrze zrozumiałem to chodzi Ci po prostu o

  appendElement = (value, value2) => this.setState({ elements: ([...this.state.elements, {value, value2}]) });

1 użytkowników online, w tym zalogowanych: 0, gości: 1