Suppose there is a parent block
class Parent extends React.Component { render() { retrun ( <div> <Child /> <Logs /> </div> ) } } //Покупка чего-либо class Child extends React.Component { state = { ... }; buy = () => { //... //Logs.latest.push(...) -Как это сделать? this.setState(...) }; render() { return ( <div> ... <button onClick={this.buy}>Купить</button> </div> ) } } //Вывод логов class Logs extends React.Component { state = { latest: [...] } render( <div> {this.state.latest.map((log) => {return (<div>{log.text}</div>)})} </div> ) } How can I make it so that when I click on Child.buy () after the purchase an entry is added to the Logs and it is updated?
You can of course store state.latest in Parent and update the array already there. But maybe there is a better solution?