There are two components, I want to change the fragment from h1 by clicking. I don’t know how to do it right, I probably need it through setState . Not sure I understood correctly how to use it.
import React from 'react'; import '../index.css' import Cover from './Cover' class Main extends React.Component { constructor(props) { super(props) state = { isClicked: false } this.changeName = changeName.bind(this); } render() { return ( <div className="main"> <input className="input" placeholder="Username" /> <button onClick={this.changeName} className="submit-button">Submit</button> </div> ) } changeName = () => { this.setState({ isClicked: true }) Cover.username = document.getElementById('input').nodeValue } } export default Main //---------------------------------------------------------------- import React from 'react'; import '../index.css' class Cover extends React.Component { constructor(props) { super(props) this.username = 'username'; } render() { return ( <div className="cover"> <img className="logo" src="./assets/logo.svg" /> <h1 className="header">Welcome on board, {{username}}!</h1> </div> ) } } export default Cover