Last active
November 24, 2019 17:15
-
-
Save VinixGonzalez/e0b016b4708134aec1a34add1992d2f2 to your computer and use it in GitHub Desktop.
App Mobx exemplo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { inject, observer } from 'mobx-react' | |
@inject('RootStore') | |
@observer | |
class App extends React.Component { | |
adicionarUsuario = () => { | |
if (this.usuario.value == '') | |
return; | |
this.props.RootStore.addUsuario(this.usuario.value); | |
this.usuario.value = ''; | |
} | |
render() { | |
const { RootStore } = this.props; | |
return ( | |
<div className="App" style={{ padding: 20 }}> | |
<h3>Usuario logado: {RootStore.usuarioLogado}</h3> | |
<h3>Total de usuários: {RootStore.listaUsuarios.length}</h3> | |
<div style={{ marginTop: 100 }}> | |
<h3>Adicionar Usuario</h3> | |
<input ref={input => this.usuario = input} type="text" /> | |
<button onClick={this.adicionarUsuario}>Adicionar</button> | |
</div> | |
<div style={{ marginTop: 100 }}> | |
<h3>Lista de Usuários</h3> | |
<ul> | |
{RootStore.listaUsuarios.map(usuario => <li>{usuario}</li>)} | |
</ul> | |
</div> | |
</div> | |
) | |
} | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment