How to update the HelloWorld element from the updateHelloWorld function and in general it is possible?
Code example:
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import registerServiceWorker from './registerServiceWorker'; function getServerData() { // Получаем данные с сервера data = new GetServerData() return data.data } function updateHelloWorld() { // Магия которая должна обновить элемент } class HelloWorld extends React.Component { render() { return ( <h1>Hello world {getServerData}</h1> ); } } class ButtonClisk extends React.Component { render() { return ( <div> <button onClick={updateHelloWorld}>Обновить</button> </div> ); } } ReactDOM.render( <div> <HelloWorld /> <ButtonClisk /> </div>, document.getElementById('root') as HTMLElement ); registerServiceWorker();
setState. But the question is not quite clear what needs to be updated - Denis Bubnov<HelloWorld />element and do not update the whole application, that is, without updating<ButtonClisk />- usersButtonCliskdoesn't know anything about theHelloWorldcomponent - this is the first. Secondly, I still do not understand what you want to update there. I think you need to read a little about React and setState . So that you understand how components can interact with each other and how to update them. - Denis Bubnov